From e80a83cf87eb79be4c2ac016d3c97709d41ee353 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 24 Jan 2024 20:43:41 -0800
Subject: feat(identity): use global store

---
 src/routes/+page.svelte | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

(limited to 'src/routes/+page.svelte')

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 @@
 <script lang="ts">
 	import { onMount } from 'svelte';
-	import { userIdentity as getUserIdentity } from '$lib/AniList/identity';
 	import AnimeList from '$lib/List/Anime/DueAnimeList.svelte';
 	import MangaListTemplate from '$lib/List/Manga/MangaListTemplate.svelte';
 	import UpcomingAnimeList from '$lib/List/Anime/UpcomingAnimeList.svelte';
-	import userIdentity from '$stores/userIdentity';
+	import userIdentity from '$stores/identity.js';
 	import settings from '$stores/settings';
 	import ListTitle from '$lib/List/ListTitle.svelte';
 	import HeadTitle from '$lib/Home/HeadTitle.svelte';
@@ -13,24 +12,7 @@
 
 	export let data;
 
-	let currentUserIdentity = {
-		name: '',
-		id: -1,
-		avatar: 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png'
-	};
-
-	onMount(async () => {
-		createHeightObserver();
-
-		if (data.user !== undefined) {
-			if ($userIdentity === '') {
-				userIdentity.set(JSON.stringify(await getUserIdentity(data.user)));
-			}
-
-			currentUserIdentity = JSON.parse($userIdentity);
-			currentUserIdentity.name = currentUserIdentity.name;
-		}
-	});
+	onMount(createHeightObserver);
 </script>
 
 <HeadTitle />
@@ -51,8 +33,8 @@
 	{:else}
 		{#if !$settings.disableUpcomingAnime}
 			<details open={!$settings.displayUpcomingAnimeCollapsed} class="list">
-				{#if currentUserIdentity.id != -1}
-					<UpcomingAnimeList user={data.user} identity={currentUserIdentity} />
+				{#if $userIdentity.id != -1}
+					<UpcomingAnimeList user={data.user} identity={$userIdentity} />
 				{:else}
 					<ListTitle custom="Upcoming Episodes" />
 
@@ -67,8 +49,8 @@
 
 		{#if !$settings.disableAnime}
 			<details open={!$settings.displayAnimeCollapsed} class="list">
-				{#if currentUserIdentity.id != -1}
-					<AnimeList user={data.user} identity={currentUserIdentity} />
+				{#if $userIdentity.id != -1}
+					<AnimeList user={data.user} identity={$userIdentity} />
 				{:else}
 					<ListTitle anime />
 
@@ -83,10 +65,10 @@
 
 		{#if !$settings.disableManga}
 			<details open={!$settings.displayMangaCollapsed} class="list">
-				{#if currentUserIdentity.id != -1}
+				{#if $userIdentity.id != -1}
 					<MangaListTemplate
 						user={data.user}
-						identity={currentUserIdentity}
+						identity={$userIdentity}
 						displayUnresolved={$settings.displayUnresolved}
 						due={true}
 					/>
-- 
cgit v1.2.3

