From c00e893e2f178d51bc18fdb5c10dcf46a3cef1d3 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 27 Aug 2023 15:52:22 -0700
Subject: feat(layout): cache user identity

---
 src/routes/+layout.svelte | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

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

diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 01ede9e0..07c5435a 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -1,8 +1,9 @@
 <script>
 	import { env } from '$env/dynamic/public';
-	import { userIdentity } from '$lib/AniList/identity';
+	import { userIdentity as getUserIdentity } from '$lib/AniList/identity';
 	import { onMount } from 'svelte';
 	import { lastActivityDate } from '$lib/AniList/activity';
+	import userIdentity from '../stores/userIdentity';
 
 	export let data;
 
@@ -11,8 +12,12 @@
 
 	onMount(async () => {
 		if (data.user !== undefined) {
-			currentUserIdentity = await userIdentity(data.user);
-			currentUserIdentity.name = `${currentUserIdentity.name}`;
+			if ($userIdentity === '') {
+				userIdentity.set(JSON.stringify(await getUserIdentity(data.user)));
+			}
+
+			currentUserIdentity = JSON.parse($userIdentity);
+			currentUserIdentity.name = currentUserIdentity.name;
 			lastActivityWasToday =
 				(await lastActivityDate(currentUserIdentity)).toDateString() === new Date().toDateString();
 		}
-- 
cgit v1.2.3

