aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-08-27 15:52:22 -0700
committerFuwn <[email protected]>2023-08-27 15:52:22 -0700
commitc00e893e2f178d51bc18fdb5c10dcf46a3cef1d3 (patch)
treef557e3f4fb71bd8e3a385ff0ec3a3845c2b481e4 /src
parentfeat(layout): username loading (diff)
downloaddue.moe-c00e893e2f178d51bc18fdb5c10dcf46a3cef1d3.tar.xz
due.moe-c00e893e2f178d51bc18fdb5c10dcf46a3cef1d3.zip
feat(layout): cache user identity
Diffstat (limited to 'src')
-rw-r--r--src/routes/+layout.svelte11
-rw-r--r--src/stores/userIdentity.ts12
2 files changed, 20 insertions, 3 deletions
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();
}
diff --git a/src/stores/userIdentity.ts b/src/stores/userIdentity.ts
new file mode 100644
index 00000000..e5018268
--- /dev/null
+++ b/src/stores/userIdentity.ts
@@ -0,0 +1,12 @@
+import { browser } from '$app/environment';
+import { writable } from 'svelte/store';
+
+const userIdentity = writable<string>(browser ? localStorage.getItem('userIdentity') ?? '' : '');
+
+userIdentity.subscribe((value) => {
+ if (browser) {
+ localStorage.setItem('userIdentity', value);
+ }
+});
+
+export default userIdentity;