aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-03 18:25:03 -0700
committerFuwn <[email protected]>2023-09-03 18:25:03 -0700
commitddc18557b5de23fee2e0723b305fd8d8de62bd17 (patch)
tree1d637c453ee627f62f2cdc63c3bb20d11f3b6b5d /src
parentrefactor(settings): remove useless triple equal (diff)
downloaddue.moe-ddc18557b5de23fee2e0723b305fd8d8de62bd17.tar.xz
due.moe-ddc18557b5de23fee2e0723b305fd8d8de62bd17.zip
feat(settings): move cache minutes to settings
Diffstat (limited to 'src')
-rw-r--r--src/lib/List/Due/AnimeList.svelte3
-rw-r--r--src/lib/List/Due/MangaList.svelte6
-rw-r--r--src/routes/settings/+page.svelte13
-rw-r--r--src/stores/cacheMangaMinutes.ts14
-rw-r--r--src/stores/cacheMinutes.ts14
-rw-r--r--src/stores/settings.ts30
6 files changed, 29 insertions, 51 deletions
diff --git a/src/lib/List/Due/AnimeList.svelte b/src/lib/List/Due/AnimeList.svelte
index 0cfd5994..1409730f 100644
--- a/src/lib/List/Due/AnimeList.svelte
+++ b/src/lib/List/Due/AnimeList.svelte
@@ -6,7 +6,6 @@
import { onDestroy, onMount } from 'svelte';
import anime from '../../../stores/anime';
import animeLastPrune from '../../../stores/mangaLastPrune';
- import cacheMinutes from '../../../stores/cacheMinutes';
import settings from '../../../stores/settings';
export let user: AniListAuthorisation;
@@ -21,7 +20,7 @@
startTime = performance.now();
endTime = -1;
animeLists = mediaListCollection(user, identity, Type.Anime, $anime, $animeLastPrune, true);
- }, Number($cacheMinutes || 10) * 1000 * 60);
+ }, Number($settings.cacheMinutes || 10) * 1000 * 60);
onMount(async () => {
startTime = performance.now();
diff --git a/src/lib/List/Due/MangaList.svelte b/src/lib/List/Due/MangaList.svelte
index 43976e0d..374d06e1 100644
--- a/src/lib/List/Due/MangaList.svelte
+++ b/src/lib/List/Due/MangaList.svelte
@@ -6,9 +6,7 @@
import chaptersLastPrune from '../../../stores/chaptersLastPrune';
import manga from '../../../stores/manga';
import { chapterDatabase } from '$lib/chapterDatabase';
- import cacheMangaMinutes from '../../../stores/cacheMangaMinutes';
import mangaLastPrune from '../../../stores/mangaLastPrune';
- import cacheMinutes from '../../../stores/cacheMinutes';
import settings from '../../../stores/settings';
export let user: AniListAuthorisation;
@@ -23,7 +21,7 @@
startTime = performance.now();
endTime = -1;
mangaLists = mediaListCollection(user, identity, Type.Manga, $manga, $mangaLastPrune);
- }, Number($cacheMinutes || 30) * 1000 * 60);
+ }, Number($settings.cacheMinutes || 30) * 1000 * 60);
onMount(async () => {
startTime = performance.now();
@@ -47,7 +45,7 @@
} else {
if (
(new Date().getTime() - Number($chaptersLastPrune)) / 1000 / 60 >
- Number($cacheMangaMinutes)
+ Number($settings.cacheMangaMinutes)
) {
const unresolved = await chapterDatabase.chapters.where('chapters').equals(-1).toArray();
const ids = unresolved.map((m) => m.id);
diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte
index 6dc4202f..39c67391 100644
--- a/src/routes/settings/+page.svelte
+++ b/src/routes/settings/+page.svelte
@@ -2,8 +2,6 @@
/* eslint svelte/no-at-html-tags: "off" */
import { chapterDatabase } from '$lib/chapterDatabase';
- import cacheMangaMinutes from '../../stores/cacheMangaMinutes';
- import cacheMinutes from '../../stores/cacheMinutes';
import manga from '../../stores/manga';
import anime from '../../stores/anime';
import settings from '../../stores/settings';
@@ -124,12 +122,19 @@
<br />
Re-cache <b>ALL</b> media keys every
- <input type="number" bind:value={$cacheMinutes} min="1" max="60" placeholder="30" /> minutes
+ <input type="number" bind:value={$settings.cacheMinutes} min="1" max="60" placeholder="30" />
+ minutes
<p />
<span>Re-cache <b>ALL</b> manga chapter counts every</span>
- <input type="number" bind:value={$cacheMangaMinutes} min="1" max="1440" placeholder="60" />
+ <input
+ type="number"
+ bind:value={$settings.cacheMangaMinutes}
+ min="1"
+ max="1440"
+ placeholder="60"
+ />
minutes
<br />
<small style="opacity: 50%;"
diff --git a/src/stores/cacheMangaMinutes.ts b/src/stores/cacheMangaMinutes.ts
deleted file mode 100644
index 6da460b2..00000000
--- a/src/stores/cacheMangaMinutes.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { browser } from '$app/environment';
-import { writable } from 'svelte/store';
-
-const cacheMangaMinutes = writable<string>(
- browser ? localStorage.getItem('cacheMangaMinutes') ?? '60' : '60'
-);
-
-cacheMangaMinutes.subscribe((value) => {
- if (browser) {
- localStorage.setItem('cacheMangaMinutes', value);
- }
-});
-
-export default cacheMangaMinutes;
diff --git a/src/stores/cacheMinutes.ts b/src/stores/cacheMinutes.ts
deleted file mode 100644
index ccea5db1..00000000
--- a/src/stores/cacheMinutes.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { browser } from '$app/environment';
-import { writable } from 'svelte/store';
-
-const cacheMinutes = writable<string>(
- browser ? localStorage.getItem('cacheMinutes') ?? '30' : '30'
-);
-
-cacheMinutes.subscribe((value) => {
- if (browser) {
- localStorage.setItem('cacheMinutes', value);
- }
-});
-
-export default cacheMinutes;
diff --git a/src/stores/settings.ts b/src/stores/settings.ts
index 30f1c34d..9396ec74 100644
--- a/src/stores/settings.ts
+++ b/src/stores/settings.ts
@@ -2,8 +2,8 @@ import { browser } from '$app/environment';
import { writable } from 'svelte/store';
interface Settings {
- // cacheMangaMinutes: number;
- // cacheMinutes: number;
+ cacheMangaMinutes: number;
+ cacheMinutes: number;
closeAnimeByDefault: boolean;
closeMangaByDefault: boolean;
displayNotStarted: boolean;
@@ -13,8 +13,8 @@ interface Settings {
}
const defaultSettings: Settings = {
- // cacheMangaMinutes: 60,
- // cacheMinutes: 30,
+ cacheMangaMinutes: 60,
+ cacheMinutes: 30,
closeAnimeByDefault: false,
closeMangaByDefault: false,
displayNotStarted: false,
@@ -24,7 +24,16 @@ const defaultSettings: Settings = {
};
const createStore = () => {
- const { subscribe, set, update } = writable<Settings>(defaultSettings);
+ const { subscribe, set, update } = writable<Settings>(
+ JSON.parse(
+ browser
+ ? localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
+ : JSON.stringify(defaultSettings)
+ )
+ );
+ let state: Settings;
+
+ subscribe((value) => (state = value));
return {
subscribe,
@@ -32,13 +41,8 @@ const createStore = () => {
update,
reset: () => set(defaultSettings),
get: () => {
- const settings = JSON.parse(
- browser
- ? localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
- : JSON.stringify(defaultSettings)
- );
const keys = Object.keys(defaultSettings);
- const settingsKeys = Object.keys(settings);
+ const settingsKeys = Object.keys(state);
if (keys.length !== settingsKeys.length) {
return defaultSettings;
@@ -50,9 +54,9 @@ const createStore = () => {
}
}
- return settings;
+ return state;
},
- setKey: (key: keyof Settings, value: any) =>
+ setKey: (key: keyof Settings, value: unknown) =>
update((settings) => ({ ...settings, [key]: value }))
};
};