aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Schedule/Days.svelte6
-rw-r--r--src/routes/user/+page.svelte3
-rw-r--r--src/stores/identity.ts19
-rw-r--r--src/stores/stateBin.ts10
4 files changed, 28 insertions, 10 deletions
diff --git a/src/lib/Schedule/Days.svelte b/src/lib/Schedule/Days.svelte
index 0eb30579..ec36be5c 100644
--- a/src/lib/Schedule/Days.svelte
+++ b/src/lib/Schedule/Days.svelte
@@ -2,6 +2,7 @@
import { browser } from "$app/environment";
import type { AniListAuthorisation } from "$lib/Data/AniList/identity";
import { mediaListCollection, Type, type Media } from "$lib/Data/AniList/media";
+import { hydrateMediaListCache } from "$lib/Data/AniList/cacheHydration";
import { findClosestMedia } from "$lib/Media/Anime/Airing/Subtitled/match";
import type {
SubsPlease,
@@ -37,7 +38,9 @@ let mediaListPromise: Promise<Media[]>;
onMount(async () => {
if (user === undefined || $identity.id === -2)
mediaListPromise = Promise.resolve([]);
- else
+ else {
+ await hydrateMediaListCache("anime");
+
mediaListPromise = mediaListCollection(
user,
$identity,
@@ -48,6 +51,7 @@ onMount(async () => {
all: true,
},
);
+ }
});
const shiftSubsPleaseSchedule = (schedule: SubsPlease["schedule"]) => {
diff --git a/src/routes/user/+page.svelte b/src/routes/user/+page.svelte
index ee7c69af..20a8d390 100644
--- a/src/routes/user/+page.svelte
+++ b/src/routes/user/+page.svelte
@@ -11,7 +11,8 @@ import localforage from "localforage";
onMount(async () => {
if (browser) {
- const user = ((await localforage.getItem("identity")) as UserIdentity).name;
+ const identity = await localforage.getItem<UserIdentity>("identity");
+ const user = identity?.name;
if (user) {
if (browser && $page.url.searchParams.get("badges") !== null) {
diff --git a/src/stores/identity.ts b/src/stores/identity.ts
index b78dd519..52e0cba7 100644
--- a/src/stores/identity.ts
+++ b/src/stores/identity.ts
@@ -12,18 +12,23 @@ export const defaultIdentity: UserIdentity = {
const createStore = () => {
const store = writable<UserIdentity>(defaultIdentity);
let state: UserIdentity = defaultIdentity;
-
- if (browser)
- localforage.getItem<UserIdentity>("identity").then((value) => {
- if (value && typeof value === "object") store.set(value);
- });
+ let hydrated = !browser;
store.subscribe((value) => {
state = value;
- if (browser) localforage.setItem("identity", value);
+ if (browser && hydrated) localforage.setItem("identity", value);
});
+ if (browser)
+ localforage.getItem<UserIdentity>("identity").then(async (value) => {
+ if (value && typeof value === "object") store.set(value);
+
+ hydrated = true;
+
+ await localforage.setItem("identity", state);
+ });
+
return {
subscribe: store.subscribe,
set: store.set,
@@ -41,7 +46,7 @@ const createStore = () => {
defaultIdentity as unknown as Record<string, unknown>
)[key];
- if (browser) localforage.setItem("identity", updatedIdentity);
+ if (browser && hydrated) localforage.setItem("identity", updatedIdentity);
return updatedIdentity;
},
diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts
index 06d34bef..1d3f5dee 100644
--- a/src/stores/stateBin.ts
+++ b/src/stores/stateBin.ts
@@ -13,14 +13,22 @@ interface StateBin {
const STORAGE_KEY = "stateBin";
const baseStore = writable<StateBin>({});
+let hydrated = !browser;
+let state: StateBin = {};
if (browser) {
localforage.getItem<StateBin>(STORAGE_KEY).then((value) => {
if (value && typeof value === "object") baseStore.set(value);
+
+ hydrated = true;
+
+ localforage.setItem(STORAGE_KEY, state);
});
baseStore.subscribe((value) => {
- localforage.setItem(STORAGE_KEY, value);
+ state = value;
+
+ if (hydrated) localforage.setItem(STORAGE_KEY, value);
});
}