diff options
| author | Fuwn <[email protected]> | 2026-03-01 16:20:51 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-01 16:21:02 -0800 |
| commit | eae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch) | |
| tree | 1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/stores | |
| parent | chore(tooling): remove legacy eslint and prettier (diff) | |
| download | due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip | |
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/airingNow.ts | 10 | ||||
| -rw-r--r-- | src/stores/anime.ts | 4 | ||||
| -rw-r--r-- | src/stores/announcementHash.ts | 8 | ||||
| -rw-r--r-- | src/stores/identity.ts | 74 | ||||
| -rw-r--r-- | src/stores/lastPruneTimes.ts | 72 | ||||
| -rw-r--r-- | src/stores/locale.ts | 110 | ||||
| -rw-r--r-- | src/stores/manga.ts | 4 | ||||
| -rw-r--r-- | src/stores/revalidateAnime.ts | 2 | ||||
| -rw-r--r-- | src/stores/settings.ts | 419 | ||||
| -rw-r--r-- | src/stores/settingsSyncPulled.ts | 2 | ||||
| -rw-r--r-- | src/stores/settingsSyncTimes.ts | 10 | ||||
| -rw-r--r-- | src/stores/stateBin.ts | 77 | ||||
| -rw-r--r-- | src/stores/subsPlease.ts | 4 | ||||
| -rw-r--r-- | src/stores/tooltipPosition.ts | 14 |
14 files changed, 417 insertions, 393 deletions
diff --git a/src/stores/airingNow.ts b/src/stores/airingNow.ts index 697001ef..b885b7a7 100644 --- a/src/stores/airingNow.ts +++ b/src/stores/airingNow.ts @@ -1,14 +1,14 @@ -import { browser } from '$app/environment'; -import { readable } from 'svelte/store'; +import { browser } from "$app/environment"; +import { readable } from "svelte/store"; const TICK_INTERVAL_MS = 30 * 1000; const airingNow = readable(Date.now(), (set) => { - if (!browser) return () => undefined; + if (!browser) return () => undefined; - const interval = setInterval(() => set(Date.now()), TICK_INTERVAL_MS); + const interval = setInterval(() => set(Date.now()), TICK_INTERVAL_MS); - return () => clearInterval(interval); + return () => clearInterval(interval); }); export default airingNow; diff --git a/src/stores/anime.ts b/src/stores/anime.ts index 116139a3..0ab4513d 100644 --- a/src/stores/anime.ts +++ b/src/stores/anime.ts @@ -1,5 +1,5 @@ -import { persistentStore } from '$lib/Utility/persistentStore'; +import { persistentStore } from "$lib/Utility/persistentStore"; -const anime = persistentStore<string>('anime', ''); +const anime = persistentStore<string>("anime", ""); export default anime; diff --git a/src/stores/announcementHash.ts b/src/stores/announcementHash.ts index 1ef178e2..0a41002f 100644 --- a/src/stores/announcementHash.ts +++ b/src/stores/announcementHash.ts @@ -1,12 +1,12 @@ -import { browser } from '$app/environment'; -import { writable } from 'svelte/store'; +import { browser } from "$app/environment"; +import { writable } from "svelte/store"; const announcementHash = writable<number>( - browser ? parseInt(localStorage.getItem('announcementHash') || '1') : 1 + browser ? parseInt(localStorage.getItem("announcementHash") || "1") : 1, ); announcementHash.subscribe((value) => { - if (browser) localStorage.setItem('announcementHash', value.toString()); + if (browser) localStorage.setItem("announcementHash", value.toString()); }); export default announcementHash; diff --git a/src/stores/identity.ts b/src/stores/identity.ts index 11c4446b..b78dd519 100644 --- a/src/stores/identity.ts +++ b/src/stores/identity.ts @@ -1,54 +1,54 @@ -import { browser } from '$app/environment'; -import type { UserIdentity } from '$lib/Data/AniList/identity'; -import { writable } from 'svelte/store'; -import localforage from 'localforage'; +import { browser } from "$app/environment"; +import type { UserIdentity } from "$lib/Data/AniList/identity"; +import { writable } from "svelte/store"; +import localforage from "localforage"; export const defaultIdentity: UserIdentity = { - name: '', - id: -2, - avatar: 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png' + name: "", + id: -2, + avatar: "https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png", }; const createStore = () => { - const store = writable<UserIdentity>(defaultIdentity); - let state: UserIdentity = defaultIdentity; + 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); - }); + if (browser) + localforage.getItem<UserIdentity>("identity").then((value) => { + if (value && typeof value === "object") store.set(value); + }); - store.subscribe((value) => { - state = value; + store.subscribe((value) => { + state = value; - if (browser) localforage.setItem('identity', value); - }); + if (browser) localforage.setItem("identity", value); + }); - return { - subscribe: store.subscribe, - set: store.set, - update: store.update, - reset: () => store.set(defaultIdentity), + return { + subscribe: store.subscribe, + set: store.set, + update: store.update, + reset: () => store.set(defaultIdentity), - get: () => { - const keys = Object.keys(defaultIdentity); - const identityKeys = Object.keys(state); - const updatedIdentity = { ...state }; + get: () => { + const keys = Object.keys(defaultIdentity); + const identityKeys = Object.keys(state); + const updatedIdentity = { ...state }; - for (const key of keys) - if (!identityKeys.includes(key)) - (updatedIdentity as unknown as Record<string, unknown>)[key] = ( - defaultIdentity as unknown as Record<string, unknown> - )[key]; + for (const key of keys) + if (!identityKeys.includes(key)) + (updatedIdentity as unknown as Record<string, unknown>)[key] = ( + defaultIdentity as unknown as Record<string, unknown> + )[key]; - if (browser) localforage.setItem('identity', updatedIdentity); + if (browser) localforage.setItem("identity", updatedIdentity); - return updatedIdentity; - }, + return updatedIdentity; + }, - setKey: (key: keyof UserIdentity, value: unknown) => - store.update((identity) => ({ ...identity, [key]: value })) - }; + setKey: (key: keyof UserIdentity, value: unknown) => + store.update((identity) => ({ ...identity, [key]: value })), + }; }; const identity = createStore(); 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(); diff --git a/src/stores/locale.ts b/src/stores/locale.ts index ae4a5107..826d717c 100644 --- a/src/stores/locale.ts +++ b/src/stores/locale.ts @@ -1,72 +1,78 @@ -import { derived, type Readable } from 'svelte/store'; -import { json } from 'svelte-i18n'; -import type { Locale } from '$lib/Locale/layout'; +import { derived, type Readable } from "svelte/store"; +import { json } from "svelte-i18n"; +import type { Locale } from "$lib/Locale/layout"; -type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R; +type FormatXMLElementFn<T, R = string | T | (string | T)[]> = ( + parts: Array<string | T>, +) => R; type InterpolationValue = - | string - | number - | boolean - | Date - | FormatXMLElementFn<unknown> - | null - | undefined; + | string + | number + | boolean + | Date + | FormatXMLElementFn<unknown> + | null + | undefined; type InterpolationValues = Record<string, InterpolationValue> | undefined; interface Options { - id?: string; - locale?: string; - format?: string; - default?: string; - values?: InterpolationValues; + id?: string; + locale?: string; + format?: string; + default?: string; + values?: InterpolationValues; } const createLocale = () => { - return derived(json, ($json) => { - return (options: Options = {}) => - new Proxy( - {}, - { - get(_target, key) { - const localisation = $json(key.toString(), options.locale); + return derived(json, ($json) => { + return (options: Options = {}) => + new Proxy( + {}, + { + get(_target, key) { + const localisation = $json(key.toString(), options.locale); - if (localisation === key.toString()) return undefined; + if (localisation === key.toString()) return undefined; - const replaceValues = ( - localisation: InterpolationValues, - values: InterpolationValues - ) => { - if (typeof localisation !== 'object' || localisation === null) return localisation; + const replaceValues = ( + localisation: InterpolationValues, + values: InterpolationValues, + ) => { + if (typeof localisation !== "object" || localisation === null) + return localisation; - const updatedLocalisation: InterpolationValues = {}; + const updatedLocalisation: InterpolationValues = {}; - for (const [key, value] of Object.entries(localisation)) { - if (typeof value === 'string') { - updatedLocalisation[key] = value.replace( - /\{(\w+)\}/g, - (match, name) => (values ? values[name] : match) as string - ); - } else { - updatedLocalisation[key] = replaceValues( - value as InterpolationValues, - values - ) as InterpolationValue; - } - } + for (const [key, value] of Object.entries(localisation)) { + if (typeof value === "string") { + updatedLocalisation[key] = value.replace( + /\{(\w+)\}/g, + (match, name) => (values ? values[name] : match) as string, + ); + } else { + updatedLocalisation[key] = replaceValues( + value as InterpolationValues, + values, + ) as InterpolationValue; + } + } - return updatedLocalisation; - }; + return updatedLocalisation; + }; - if (options.values) - return replaceValues(localisation as unknown as InterpolationValues, options.values); + if (options.values) + return replaceValues( + localisation as unknown as InterpolationValues, + options.values, + ); - return localisation; - } - } - ); - }) as Readable<(options?: Options) => Locale>; + return localisation; + }, + }, + ); + }) as Readable<(options?: Options) => Locale>; }; const locale = createLocale(); diff --git a/src/stores/manga.ts b/src/stores/manga.ts index 84b19665..e6637258 100644 --- a/src/stores/manga.ts +++ b/src/stores/manga.ts @@ -1,5 +1,5 @@ -import { persistentStore } from '$lib/Utility/persistentStore'; +import { persistentStore } from "$lib/Utility/persistentStore"; -const manga = persistentStore<string>('manga', ''); +const manga = persistentStore<string>("manga", ""); export default manga; diff --git a/src/stores/revalidateAnime.ts b/src/stores/revalidateAnime.ts index b20a5374..acbbf367 100644 --- a/src/stores/revalidateAnime.ts +++ b/src/stores/revalidateAnime.ts @@ -1,4 +1,4 @@ -import { writable } from 'svelte/store'; +import { writable } from "svelte/store"; const revalidateAnime = writable<boolean>(false); diff --git a/src/stores/settings.ts b/src/stores/settings.ts index ec470524..e960eff6 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -1,220 +1,233 @@ -import { browser } from '$app/environment'; -import root from '$lib/Utility/root'; -import { get, writable } from 'svelte/store'; -import settingsSyncPulled from './settingsSyncPulled'; -import settingsSyncTimes from './settingsSyncTimes'; -import identity from './identity'; +import { browser } from "$app/environment"; +import root from "$lib/Utility/root"; +import { get, writable } from "svelte/store"; +import settingsSyncPulled from "./settingsSyncPulled"; +import settingsSyncTimes from "./settingsSyncTimes"; +import identity from "./identity"; -const VERSION = '1.0.1'; +const VERSION = "1.0.1"; export interface Settings { - cacheMangaMinutes: number; - cacheMinutes: number; - displayUpcomingAnimeCollapsed: boolean; - displayAnimeCollapsed: boolean; - displayMangaCollapsed: boolean; - displayNotStarted: boolean; - displayUnresolved: boolean; - calculateChaptersRoundedDown: boolean; - displayOutboundLinksTo: 'anilist' | 'livechartme' | 'animeschedule' | 'myanimelist'; - displayPausedMedia: boolean; - displayLimitListHeight: boolean; - displaySocialButton: boolean; - calculateGuessingDisabled: boolean; - displayHoverNavigation: boolean; - displayTitleFormat: 'english' | 'romaji' | 'native'; - calculateGuessMethod: 'median' | 'iqr_median' | 'iqr_mode' | 'mode'; - calculateDisableOutOfDateVolumeWarning: boolean; - calculatePreferNativeChapterCount: boolean; - displayPlannedAnime: boolean; - displayFurigana: boolean; - displayAoButa: - | 'kaede' - | 'mai' - | 'mai_2' - | 'nodoka' - | 'rio' - | 'sakuta' - | 'shouko' - | 'tomoe' - | 'random' - | 'none'; - disableManga: boolean; - disableAnime: boolean; - disableUpcomingAnime: boolean; - display24HourTime: boolean; - displayCountdownRightAligned: boolean; - displayNativeCountdown: boolean; - displayHoverCover: boolean; - displayDisableAnimations: boolean; - displayDisableNotifications: boolean; - displayCoverModeAnime: boolean; - displayCoverModeManga: boolean; - displayCoverWidth: number; - displayShortCountdown: boolean; - displayScheduleListMode: boolean; - displayLanguage: 'en' | 'ja'; - displayDisableLastActivityWarning: boolean; - settingsSync: boolean; - settingsVersion?: string; - displayBlurAdultContent: boolean; - displayCopyMediaTitleNotLink: boolean; - displayTotalDueEpisodes: boolean; - displayTotalEpisodes: boolean; - displayAniListNotifications: boolean; - displayFiltersIncludeCompleted: boolean; - displayDataSaver: boolean; - debugDummyLists: boolean; - displayScheduleFilterList: boolean; - displayReverseSort: boolean; - displayAnimeSort: 'difference' | 'start_date' | 'end_date' | 'time_remaining'; - displayMediaListFilter: boolean; - displayCustomCSS: string; - displayMediaRoulette: boolean; + cacheMangaMinutes: number; + cacheMinutes: number; + displayUpcomingAnimeCollapsed: boolean; + displayAnimeCollapsed: boolean; + displayMangaCollapsed: boolean; + displayNotStarted: boolean; + displayUnresolved: boolean; + calculateChaptersRoundedDown: boolean; + displayOutboundLinksTo: + | "anilist" + | "livechartme" + | "animeschedule" + | "myanimelist"; + displayPausedMedia: boolean; + displayLimitListHeight: boolean; + displaySocialButton: boolean; + calculateGuessingDisabled: boolean; + displayHoverNavigation: boolean; + displayTitleFormat: "english" | "romaji" | "native"; + calculateGuessMethod: "median" | "iqr_median" | "iqr_mode" | "mode"; + calculateDisableOutOfDateVolumeWarning: boolean; + calculatePreferNativeChapterCount: boolean; + displayPlannedAnime: boolean; + displayFurigana: boolean; + displayAoButa: + | "kaede" + | "mai" + | "mai_2" + | "nodoka" + | "rio" + | "sakuta" + | "shouko" + | "tomoe" + | "random" + | "none"; + disableManga: boolean; + disableAnime: boolean; + disableUpcomingAnime: boolean; + display24HourTime: boolean; + displayCountdownRightAligned: boolean; + displayNativeCountdown: boolean; + displayHoverCover: boolean; + displayDisableAnimations: boolean; + displayDisableNotifications: boolean; + displayCoverModeAnime: boolean; + displayCoverModeManga: boolean; + displayCoverWidth: number; + displayShortCountdown: boolean; + displayScheduleListMode: boolean; + displayLanguage: "en" | "ja"; + displayDisableLastActivityWarning: boolean; + settingsSync: boolean; + settingsVersion?: string; + displayBlurAdultContent: boolean; + displayCopyMediaTitleNotLink: boolean; + displayTotalDueEpisodes: boolean; + displayTotalEpisodes: boolean; + displayAniListNotifications: boolean; + displayFiltersIncludeCompleted: boolean; + displayDataSaver: boolean; + debugDummyLists: boolean; + displayScheduleFilterList: boolean; + displayReverseSort: boolean; + displayAnimeSort: "difference" | "start_date" | "end_date" | "time_remaining"; + displayMediaListFilter: boolean; + displayCustomCSS: string; + displayMediaRoulette: boolean; } const defaultSettings: Settings = { - // Display - displayOutboundLinksTo: 'anilist', - displayPausedMedia: true, - displayPlannedAnime: true, - displayLimitListHeight: false, - displaySocialButton: false, - displayUnresolved: false, - displayTitleFormat: 'english', - displayFurigana: false, - displayHoverNavigation: false, - displayNotStarted: false, - displayUpcomingAnimeCollapsed: false, - displayAnimeCollapsed: false, - displayMangaCollapsed: false, - displayAoButa: 'none', - disableManga: false, - disableAnime: false, - disableUpcomingAnime: false, - display24HourTime: false, - displayCountdownRightAligned: false, - displayNativeCountdown: false, - displayHoverCover: false, - displayDisableAnimations: false, - displayDisableNotifications: false, - displayCoverModeAnime: true, - displayCoverModeManga: true, - displayCoverWidth: 100, // 116.609 - displayShortCountdown: false, - displayScheduleListMode: false, - displayLanguage: 'en', - displayDisableLastActivityWarning: false, - displayBlurAdultContent: true, - displayCopyMediaTitleNotLink: false, - displayTotalDueEpisodes: false, - displayTotalEpisodes: false, - displayAniListNotifications: false, - displayFiltersIncludeCompleted: false, - displayDataSaver: false, - displayScheduleFilterList: false, - displayReverseSort: false, - displayAnimeSort: 'time_remaining', - displayMediaListFilter: false, - displayCustomCSS: '', - displayMediaRoulette: false, - - // Debug - debugDummyLists: false, - - // Calculation - calculateChaptersRoundedDown: true, - calculateDisableOutOfDateVolumeWarning: false, - calculateGuessingDisabled: true, - calculateGuessMethod: 'iqr_mode', - calculatePreferNativeChapterCount: false, - - // Cache - cacheMangaMinutes: 120, - cacheMinutes: 30, - - // Sync - settingsSync: false, - settingsVersion: VERSION + // Display + displayOutboundLinksTo: "anilist", + displayPausedMedia: true, + displayPlannedAnime: true, + displayLimitListHeight: false, + displaySocialButton: false, + displayUnresolved: false, + displayTitleFormat: "english", + displayFurigana: false, + displayHoverNavigation: false, + displayNotStarted: false, + displayUpcomingAnimeCollapsed: false, + displayAnimeCollapsed: false, + displayMangaCollapsed: false, + displayAoButa: "none", + disableManga: false, + disableAnime: false, + disableUpcomingAnime: false, + display24HourTime: false, + displayCountdownRightAligned: false, + displayNativeCountdown: false, + displayHoverCover: false, + displayDisableAnimations: false, + displayDisableNotifications: false, + displayCoverModeAnime: true, + displayCoverModeManga: true, + displayCoverWidth: 100, // 116.609 + displayShortCountdown: false, + displayScheduleListMode: false, + displayLanguage: "en", + displayDisableLastActivityWarning: false, + displayBlurAdultContent: true, + displayCopyMediaTitleNotLink: false, + displayTotalDueEpisodes: false, + displayTotalEpisodes: false, + displayAniListNotifications: false, + displayFiltersIncludeCompleted: false, + displayDataSaver: false, + displayScheduleFilterList: false, + displayReverseSort: false, + displayAnimeSort: "time_remaining", + displayMediaListFilter: false, + displayCustomCSS: "", + displayMediaRoulette: false, + + // Debug + debugDummyLists: false, + + // Calculation + calculateChaptersRoundedDown: true, + calculateDisableOutOfDateVolumeWarning: false, + calculateGuessingDisabled: true, + calculateGuessMethod: "iqr_mode", + calculatePreferNativeChapterCount: false, + + // Cache + cacheMangaMinutes: 120, + cacheMinutes: 30, + + // Sync + settingsSync: false, + settingsVersion: VERSION, }; const createStore = () => { - const initialValue = browser - ? JSON.parse(localStorage.getItem('settings') || JSON.stringify(defaultSettings)) - : defaultSettings; - const store = writable<Settings>(initialValue); - let state: Settings = initialValue; - - store.subscribe((value) => { - state = value; - - if (browser) localStorage.setItem('settings', JSON.stringify(value)); - }); - - return { - subscribe: store.subscribe, - set: store.set, - update: store.update, - reset: () => store.set(defaultSettings), - - get: () => { - const keys = Object.keys(defaultSettings); - const settingsKeys = Object.keys(state); - const updatedSettings = { ...state }; - - for (const key of keys) - if (!settingsKeys.includes(key)) - (updatedSettings as unknown as Record<string, unknown>)[key] = ( - defaultSettings as unknown as Record<string, unknown> - )[key]; - - if (browser) localStorage.setItem('settings', JSON.stringify(updatedSettings)); - - return updatedSettings; - }, - - setKey: (key: keyof Settings, value: unknown) => - store.update((settings) => ({ ...settings, [key]: value })) - }; + const initialValue = browser + ? JSON.parse( + localStorage.getItem("settings") || JSON.stringify(defaultSettings), + ) + : defaultSettings; + const store = writable<Settings>(initialValue); + let state: Settings = initialValue; + + store.subscribe((value) => { + state = value; + + if (browser) localStorage.setItem("settings", JSON.stringify(value)); + }); + + return { + subscribe: store.subscribe, + set: store.set, + update: store.update, + reset: () => store.set(defaultSettings), + + get: () => { + const keys = Object.keys(defaultSettings); + const settingsKeys = Object.keys(state); + const updatedSettings = { ...state }; + + for (const key of keys) + if (!settingsKeys.includes(key)) + (updatedSettings as unknown as Record<string, unknown>)[key] = ( + defaultSettings as unknown as Record<string, unknown> + )[key]; + + if (browser) + localStorage.setItem("settings", JSON.stringify(updatedSettings)); + + return updatedSettings; + }, + + setKey: (key: keyof Settings, value: unknown) => + store.update((settings) => ({ ...settings, [key]: value })), + }; }; const settings = createStore(); settings.subscribe((value) => { - if (!browser) return; - - if (value.settingsSync && get(settingsSyncPulled) === true) { - fetch(root(`/api/configuration?id=${get(identity).id}`)).then((response) => { - if (response.ok) - response.json().then((data) => { - const isEqualsJson = (firstObject: Settings, secondObject: Settings) => { - type AnyObject = { [key: string]: unknown }; - - return ( - Object.keys(firstObject).length === Object.keys(secondObject).length && - Object.keys(firstObject).every( - (key) => - (firstObject as unknown as AnyObject)[key] === - (secondObject as unknown as AnyObject)[key] - ) - ); - }; - - if (data?.configuration && !isEqualsJson(data.configuration, value)) - fetch(root(`/api/configuration`), { - method: 'PUT', - body: JSON.stringify(value) - }).then((response) => { - if (response.ok) console.log('Pushed local configuration'); - - settingsSyncTimes.update((times) => ({ - ...times, - lastPush: new Date() - })); - }); - }); - }); - } + if (!browser) return; + + if (value.settingsSync && get(settingsSyncPulled) === true) { + fetch(root(`/api/configuration?id=${get(identity).id}`)).then( + (response) => { + if (response.ok) + response.json().then((data) => { + const isEqualsJson = ( + firstObject: Settings, + secondObject: Settings, + ) => { + type AnyObject = { [key: string]: unknown }; + + return ( + Object.keys(firstObject).length === + Object.keys(secondObject).length && + Object.keys(firstObject).every( + (key) => + (firstObject as unknown as AnyObject)[key] === + (secondObject as unknown as AnyObject)[key], + ) + ); + }; + + if (data?.configuration && !isEqualsJson(data.configuration, value)) + fetch(root(`/api/configuration`), { + method: "PUT", + body: JSON.stringify(value), + }).then((response) => { + if (response.ok) console.log("Pushed local configuration"); + + settingsSyncTimes.update((times) => ({ + ...times, + lastPush: new Date(), + })); + }); + }); + }, + ); + } }); export default settings; diff --git a/src/stores/settingsSyncPulled.ts b/src/stores/settingsSyncPulled.ts index 1e9c3333..bc440579 100644 --- a/src/stores/settingsSyncPulled.ts +++ b/src/stores/settingsSyncPulled.ts @@ -1,4 +1,4 @@ -import { writable } from 'svelte/store'; +import { writable } from "svelte/store"; const settingsSyncPulled = writable<boolean>(false); diff --git a/src/stores/settingsSyncTimes.ts b/src/stores/settingsSyncTimes.ts index 8b4d355b..c9b0ab9a 100644 --- a/src/stores/settingsSyncTimes.ts +++ b/src/stores/settingsSyncTimes.ts @@ -1,13 +1,13 @@ -import { writable } from 'svelte/store'; +import { writable } from "svelte/store"; interface SettingsSyncTimes { - lastPush: Date; - lastPull: Date; + lastPush: Date; + lastPull: Date; } const settingsSyncPulled = writable<SettingsSyncTimes>({ - lastPush: new Date(), - lastPull: new Date() + lastPush: new Date(), + lastPull: new Date(), }); export default settingsSyncPulled; diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts index f724860a..06d34bef 100644 --- a/src/stores/stateBin.ts +++ b/src/stores/stateBin.ts @@ -1,61 +1,62 @@ -import { browser } from '$app/environment'; -import { writable, get, type Writable } from 'svelte/store'; -import localforage from 'localforage'; +import { browser } from "$app/environment"; +import { writable, get, type Writable } from "svelte/store"; +import localforage from "localforage"; interface StateBin { - dueAnimeListOpen?: boolean; - upcomingAnimeListOpen?: boolean; - dueMangaListOpen?: boolean; - completedAnimeListOpen?: boolean; - completedMangaListOpen?: boolean; - [key: string]: boolean | string | undefined; + dueAnimeListOpen?: boolean; + upcomingAnimeListOpen?: boolean; + dueMangaListOpen?: boolean; + completedAnimeListOpen?: boolean; + completedMangaListOpen?: boolean; + [key: string]: boolean | string | undefined; } -const STORAGE_KEY = 'stateBin'; +const STORAGE_KEY = "stateBin"; const baseStore = writable<StateBin>({}); if (browser) { - localforage.getItem<StateBin>(STORAGE_KEY).then((value) => { - if (value && typeof value === 'object') baseStore.set(value); - }); + localforage.getItem<StateBin>(STORAGE_KEY).then((value) => { + if (value && typeof value === "object") baseStore.set(value); + }); - baseStore.subscribe((value) => { - localforage.setItem(STORAGE_KEY, value); - }); + baseStore.subscribe((value) => { + localforage.setItem(STORAGE_KEY, value); + }); } const createProxyStore = (store: Writable<StateBin>) => { - return new Proxy(store, { - get(target, prop: string) { - if (prop in target) return (target as unknown as Record<string, unknown>)[prop]; + return new Proxy(store, { + get(target, prop: string) { + if (prop in target) + return (target as unknown as Record<string, unknown>)[prop]; - const derivedKey = writable(get(store)[prop]); + const derivedKey = writable(get(store)[prop]); - derivedKey.subscribe((value) => { - const state = get(store); - const updatedState = { ...state }; + derivedKey.subscribe((value) => { + const state = get(store); + const updatedState = { ...state }; - if (value === null || value === undefined) delete updatedState[prop]; - else updatedState[prop] = value; + if (value === null || value === undefined) delete updatedState[prop]; + else updatedState[prop] = value; - store.set(updatedState); - }); + store.set(updatedState); + }); - return derivedKey; - }, + return derivedKey; + }, - set(_, prop: string, value) { - const state = get(store); - const updatedState = { ...state }; + set(_, prop: string, value) { + const state = get(store); + const updatedState = { ...state }; - if (value === null || value === undefined) delete updatedState[prop]; - else updatedState[prop] = value; + if (value === null || value === undefined) delete updatedState[prop]; + else updatedState[prop] = value; - store.set(updatedState); + store.set(updatedState); - return true; - } - }); + return true; + }, + }); }; const stateBin = createProxyStore(baseStore); diff --git a/src/stores/subsPlease.ts b/src/stores/subsPlease.ts index 1006ce25..df36ff68 100644 --- a/src/stores/subsPlease.ts +++ b/src/stores/subsPlease.ts @@ -1,5 +1,5 @@ -import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease'; -import { writable } from 'svelte/store'; +import type { SubsPlease } from "$lib/Media/Anime/Airing/Subtitled/subsPlease"; +import { writable } from "svelte/store"; const subsPlease = writable<SubsPlease>(undefined); diff --git a/src/stores/tooltipPosition.ts b/src/stores/tooltipPosition.ts index ce523210..c9883d12 100644 --- a/src/stores/tooltipPosition.ts +++ b/src/stores/tooltipPosition.ts @@ -1,12 +1,12 @@ -import { cubicOut } from 'svelte/easing'; -import { tweened } from 'svelte/motion'; +import { cubicOut } from "svelte/easing"; +import { tweened } from "svelte/motion"; const tooltipPosition = tweened( - { x: 0, y: 0 }, - { - duration: 200 * 1.75, - easing: cubicOut - } + { x: 0, y: 0 }, + { + duration: 200 * 1.75, + easing: cubicOut, + }, ); export default tooltipPosition; |