auth: use set and update

This commit is contained in:
Xylight committed 2024-07-19 11:28:42 -07:00
1 parent 35ea654762
commit 0cdb91b20b
3 files changed
+24 -6

No files matched your search

+7 -6
View File
@@ -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<Writable<ProfileData>, Profile>(
export let profile: Readable<Profile> = 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<Writable<ProfileData>, Profile>(
fetchUser.prevProfile = profile.id
checkInbox()
update(() => profile)
})
.catch((e) => {
fetchUser.loading = false
@@ -143,9 +147,6 @@ export let profile = derived<Writable<ProfileData>, Profile>(
}
}
instance.set(profile.instance)
return profile
}
)
@@ -0,0 +1 @@
<slot />
@@ -0,0 +1,16 @@
<script lang="ts">
import { profile } from '$lib/auth'
import { t } from '$lib/translations'
import { Spinner } from 'mono-svelte'
</script>
<svelte:head>
<title>{$t('profile.subscribed')}</title>
</svelte:head>
{#if $profile?.user}{:else}
<div class="h-full w-full flex flex-col justify-center items-center">
<Spinner width={40} />
<span>{$t('toast.userLoading')}</span>
</div>
{/if}