From 0cdb91b20b9ef444556b5a5213587998a523c789 Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 19 Jul 2024 11:28:42 -0700 Subject: [PATCH] auth: use set and update --- src/lib/auth.ts | 13 +++++++------ .../subscriptions/+layout@.svelte | 1 + .../(subscriptions)/subscriptions/+page.svelte | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/routes/profile/(subscriptions)/subscriptions/+layout@.svelte create mode 100644 src/routes/profile/(subscriptions)/subscriptions/+page.svelte diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 3f31ef3f..8c9b3709 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -13,7 +13,7 @@ import { type MyUserInfo, type Community, } from 'lemmy-js-client' -import { derived, get, writable, type Writable } from 'svelte/store' +import { derived, get, writable, type Readable, type Writable } from 'svelte/store' import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js' import { browser } from '$app/environment' import { env } from '$env/dynamic/public' @@ -96,12 +96,15 @@ let fetchUser = { prevProfile: -1 } -export let profile = derived, Profile>( +export let profile: Readable = derived( profileData, - (pd) => { + (pd, set, update) => { const profile = pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile() + instance.set(profile.instance) + set(profile) + if (profile?.jwt) { if ((profile.id != fetchUser.prevProfile) && !fetchUser.loading) { site.set(undefined) @@ -127,6 +130,7 @@ export let profile = derived, Profile>( fetchUser.prevProfile = profile.id checkInbox() + update(() => profile) }) .catch((e) => { fetchUser.loading = false @@ -143,9 +147,6 @@ export let profile = derived, Profile>( } } - instance.set(profile.instance) - - return profile } ) diff --git a/src/routes/profile/(subscriptions)/subscriptions/+layout@.svelte b/src/routes/profile/(subscriptions)/subscriptions/+layout@.svelte new file mode 100644 index 00000000..4fa864ce --- /dev/null +++ b/src/routes/profile/(subscriptions)/subscriptions/+layout@.svelte @@ -0,0 +1 @@ + diff --git a/src/routes/profile/(subscriptions)/subscriptions/+page.svelte b/src/routes/profile/(subscriptions)/subscriptions/+page.svelte new file mode 100644 index 00000000..05a0ac83 --- /dev/null +++ b/src/routes/profile/(subscriptions)/subscriptions/+page.svelte @@ -0,0 +1,16 @@ + + + + {$t('profile.subscribed')} + + +{#if $profile?.user}{:else} +
+ + {$t('toast.userLoading')} +
+{/if}