aboutsummaryrefslogtreecommitdiff
path: root/src/stores/lastPruneTimes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/lastPruneTimes.ts')
-rw-r--r--src/stores/lastPruneTimes.ts72
1 files changed, 38 insertions, 34 deletions
diff --git a/src/stores/lastPruneTimes.ts b/src/stores/lastPruneTimes.ts
index 212f2bc9..4741201e 100644
--- a/src/stores/lastPruneTimes.ts
+++ b/src/stores/lastPruneTimes.ts
@@ -1,54 +1,58 @@
-import { browser } from '$app/environment';
-import { writable } from 'svelte/store';
-import localforage from 'localforage';
+import { browser } from "$app/environment";
+import { writable } from "svelte/store";
+import localforage from "localforage";
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 store = writable<LastPruneTimes>(defaultTimes);
- let state: LastPruneTimes = defaultTimes;
+ const store = writable<LastPruneTimes>(defaultTimes);
+ let state: LastPruneTimes = defaultTimes;
- if (browser)
- localforage.getItem<LastPruneTimes>('lastPruneTimes').then((value) => {
- if (value && Object.keys(value).length === Object.keys(defaultTimes).length) store.set(value);
- });
+ if (browser)
+ localforage.getItem<LastPruneTimes>("lastPruneTimes").then((value) => {
+ if (
+ value &&
+ Object.keys(value).length === Object.keys(defaultTimes).length
+ )
+ store.set(value);
+ });
- store.subscribe((value) => {
- state = value;
+ store.subscribe((value) => {
+ state = value;
- if (browser) localforage.setItem('lastPruneTimes', value);
- });
+ if (browser) localforage.setItem("lastPruneTimes", value);
+ });
- return {
- subscribe: store.subscribe,
- set: store.set,
- update: store.update,
- reset: () => store.set(defaultTimes),
+ return {
+ subscribe: store.subscribe,
+ set: store.set,
+ update: store.update,
+ reset: () => store.set(defaultTimes),
- get: () => {
- const keys = Object.keys(defaultTimes);
- const stateKeys = Object.keys(state);
+ get: () => {
+ const keys = Object.keys(defaultTimes);
+ const stateKeys = Object.keys(state);
- if (keys.length !== stateKeys.length) return defaultTimes;
+ if (keys.length !== stateKeys.length) return defaultTimes;
- for (const key of keys) if (!stateKeys.includes(key)) return defaultTimes;
+ for (const key of keys) if (!stateKeys.includes(key)) return defaultTimes;
- return state;
- },
+ return state;
+ },
- setKey: (key: keyof LastPruneTimes, value: number) =>
- store.update((times) => ({ ...times, [key]: value }))
- };
+ setKey: (key: keyof LastPruneTimes, value: number) =>
+ store.update((times) => ({ ...times, [key]: value })),
+ };
};
const lastPruneTimes = createStore();