aboutsummaryrefslogtreecommitdiff
path: root/src/stores/lastPruneTimes.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-10-09 00:41:20 -0700
committerFuwn <[email protected]>2024-10-09 00:41:43 -0700
commit998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch)
tree50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/stores/lastPruneTimes.ts
parentfeat(graphql): add badgeCount field (diff)
downloaddue.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz
due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/stores/lastPruneTimes.ts')
-rw-r--r--src/stores/lastPruneTimes.ts72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/stores/lastPruneTimes.ts b/src/stores/lastPruneTimes.ts
index 7f3a8b8d..802ad86e 100644
--- a/src/stores/lastPruneTimes.ts
+++ b/src/stores/lastPruneTimes.ts
@@ -2,53 +2,53 @@ import { browser } from '$app/environment';
import { writable } from 'svelte/store';
interface LastPruneTimes {
- anime: number;
- chapters: number;
- manga: number;
+ anime: number;
+ chapters: number;
+ manga: number;
}
const defaultTimes: LastPruneTimes = {
- anime: 1,
- chapters: 1,
- manga: 1
+ anime: 1,
+ chapters: 1,
+ manga: 1
};
const createStore = () => {
- const { subscribe, set, update } = writable<LastPruneTimes>(
- JSON.parse(
- browser
- ? localStorage.getItem('lastPruneTimes') ?? JSON.stringify(defaultTimes)
- : JSON.stringify(defaultTimes)
- )
- );
- let state: LastPruneTimes;
-
- subscribe((value) => (state = value));
-
- return {
- subscribe,
- set,
- update,
- reset: () => set(defaultTimes),
- get: () => {
- const keys = Object.keys(defaultTimes);
- const lastPruneTimesKeys = Object.keys(state);
-
- if (keys.length !== lastPruneTimesKeys.length) return defaultTimes;
-
- for (const key of keys) if (!lastPruneTimesKeys.includes(key)) return defaultTimes;
-
- return state;
- },
- setKey: (key: keyof LastPruneTimes, value: unknown) =>
- update((lastPruneTimes) => ({ ...lastPruneTimes, [key]: value }))
- };
+ const { subscribe, set, update } = writable<LastPruneTimes>(
+ JSON.parse(
+ browser
+ ? localStorage.getItem('lastPruneTimes') ?? JSON.stringify(defaultTimes)
+ : JSON.stringify(defaultTimes)
+ )
+ );
+ let state: LastPruneTimes;
+
+ subscribe((value) => (state = value));
+
+ return {
+ subscribe,
+ set,
+ update,
+ reset: () => set(defaultTimes),
+ get: () => {
+ const keys = Object.keys(defaultTimes);
+ const lastPruneTimesKeys = Object.keys(state);
+
+ if (keys.length !== lastPruneTimesKeys.length) return defaultTimes;
+
+ for (const key of keys) if (!lastPruneTimesKeys.includes(key)) return defaultTimes;
+
+ return state;
+ },
+ setKey: (key: keyof LastPruneTimes, value: unknown) =>
+ update((lastPruneTimes) => ({ ...lastPruneTimes, [key]: value }))
+ };
};
const lastPruneTimes = createStore();
lastPruneTimes.subscribe((value) => {
- if (browser) localStorage.setItem('lastPruneTimes', JSON.stringify(value));
+ if (browser) localStorage.setItem('lastPruneTimes', JSON.stringify(value));
});
export default lastPruneTimes;