From e80a83cf87eb79be4c2ac016d3c97709d41ee353 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 24 Jan 2024 20:43:41 -0800 Subject: feat(identity): use global store --- src/routes/+layout.svelte | 24 ++++++++---------------- src/routes/+page.svelte | 34 ++++++++-------------------------- src/routes/completed/+page.svelte | 30 ++++++------------------------ 3 files changed, 22 insertions(+), 66 deletions(-) (limited to 'src/routes') diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 5c01cb98..3b243232 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,7 +2,7 @@ import { env } from '$env/dynamic/public'; import { userIdentity as getUserIdentity } from '$lib/AniList/identity'; import { onMount } from 'svelte'; - import userIdentity from '$stores/userIdentity'; + import userIdentity from '$stores/identity'; import settings from '$stores/settings'; import { browser } from '$app/environment'; import HeadTitle from '$lib/Home/HeadTitle.svelte'; @@ -27,11 +27,6 @@ $: i18nLocale.set($settings.displayLanguage); - let currentUserIdentity = { - name: '', - id: -1, - avatar: 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png' - }; const navigationOrder = ['/', '/completed', '/schedule', '/updates', '/tools', '/settings']; const previousPage: Readable = readable(null, (set) => { const unsubscribe = navigating.subscribe(($navigating) => { @@ -59,12 +54,7 @@ settings.get(); if (data.user !== undefined) { - if ($userIdentity === '') { - userIdentity.set(JSON.stringify(await getUserIdentity(data.user))); - } - - currentUserIdentity = JSON.parse($userIdentity); - currentUserIdentity.name = currentUserIdentity.name; + if ($userIdentity.id === -1) userIdentity.set(await getUserIdentity(data.user)); } }); @@ -88,7 +78,7 @@ | {#if data.user} - + {$locale().navigation.profile} {/if} @@ -111,8 +101,8 @@ {$locale().navigation.logOut} {#if data.user} - - Avatar + + Avatar {/if} {/if} @@ -122,7 +112,9 @@

- + {#if $userIdentity.id !== -1} + + {/if} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 9d31b7a5..d3f7d5f9 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,10 +1,9 @@ @@ -51,8 +33,8 @@ {:else} {#if !$settings.disableUpcomingAnime}

- {#if currentUserIdentity.id != -1} - + {#if $userIdentity.id != -1} + {:else} @@ -67,8 +49,8 @@ {#if !$settings.disableAnime}
- {#if currentUserIdentity.id != -1} - + {#if $userIdentity.id != -1} + {:else} @@ -83,10 +65,10 @@ {#if !$settings.disableManga}
- {#if currentUserIdentity.id != -1} + {#if $userIdentity.id != -1} diff --git a/src/routes/completed/+page.svelte b/src/routes/completed/+page.svelte index 60549788..d1e0172f 100644 --- a/src/routes/completed/+page.svelte +++ b/src/routes/completed/+page.svelte @@ -1,7 +1,6 @@ @@ -41,8 +23,8 @@ Please log in to view due media. {:else}
- {#if currentUserIdentity.id != -1} - + {#if $userIdentity.id != -1} + {:else} @@ -51,10 +33,10 @@
- {#if currentUserIdentity.id != -1} + {#if $userIdentity.id != -1} -- cgit v1.2.3