diff options
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/anime.ts | 2 | ||||
| -rw-r--r-- | src/stores/announcementHash.ts | 4 | ||||
| -rw-r--r-- | src/stores/identity.ts | 74 | ||||
| -rw-r--r-- | src/stores/lastPruneTimes.ts | 72 | ||||
| -rw-r--r-- | src/stores/locale.ts | 96 | ||||
| -rw-r--r-- | src/stores/manga.ts | 2 | ||||
| -rw-r--r-- | src/stores/settings.ts | 352 | ||||
| -rw-r--r-- | src/stores/settingsSyncTimes.ts | 8 | ||||
| -rw-r--r-- | src/stores/tooltipPosition.ts | 10 |
9 files changed, 310 insertions, 310 deletions
diff --git a/src/stores/anime.ts b/src/stores/anime.ts index 5e4cd251..f9b649a0 100644 --- a/src/stores/anime.ts +++ b/src/stores/anime.ts @@ -4,7 +4,7 @@ import { writable } from 'svelte/store'; const anime = writable<string>(browser ? localStorage.getItem('anime') ?? '' : ''); anime.subscribe((value) => { - if (browser) localStorage.setItem('anime', value); + if (browser) localStorage.setItem('anime', value); }); export default anime; diff --git a/src/stores/announcementHash.ts b/src/stores/announcementHash.ts index 4a44d670..0ff57b3b 100644 --- a/src/stores/announcementHash.ts +++ b/src/stores/announcementHash.ts @@ -2,11 +2,11 @@ import { browser } from '$app/environment'; import { writable } from 'svelte/store'; const announcementHash = writable<number>( - browser ? parseInt(localStorage.getItem('announcementHash') || '1') : 0 + browser ? parseInt(localStorage.getItem('announcementHash') || '1') : 0 ); 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 c89df97b..1b0aee90 100644 --- a/src/stores/identity.ts +++ b/src/stores/identity.ts @@ -3,51 +3,51 @@ import type { UserIdentity } from '$lib/Data/AniList/identity'; import { writable } from 'svelte/store'; 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 { subscribe, set, update } = writable<UserIdentity>( - JSON.parse( - browser - ? localStorage.getItem('identity') ?? JSON.stringify(defaultIdentity) - : JSON.stringify(defaultIdentity) - ) - ); - let state: UserIdentity; - - subscribe((value) => (state = value)); - - return { - subscribe, - set, - update, - reset: () => set(defaultIdentity), - get: () => { - const keys = Object.keys(defaultIdentity); - const identityKeys = Object.keys(state); - const updatedIdentity = { ...state }; - - for (const key of keys) - if (!identityKeys.includes(key)) - (updatedIdentity[key as keyof UserIdentity] as unknown) = - defaultIdentity[key as keyof UserIdentity]; - - if (browser) localStorage.setItem('identity', JSON.stringify(updatedIdentity)); - - return updatedIdentity; - }, - setKey: (key: keyof UserIdentity, value: unknown) => - update((identity) => ({ ...identity, [key]: value })) - }; + const { subscribe, set, update } = writable<UserIdentity>( + JSON.parse( + browser + ? localStorage.getItem('identity') ?? JSON.stringify(defaultIdentity) + : JSON.stringify(defaultIdentity) + ) + ); + let state: UserIdentity; + + subscribe((value) => (state = value)); + + return { + subscribe, + set, + update, + reset: () => set(defaultIdentity), + get: () => { + const keys = Object.keys(defaultIdentity); + const identityKeys = Object.keys(state); + const updatedIdentity = { ...state }; + + for (const key of keys) + if (!identityKeys.includes(key)) + (updatedIdentity[key as keyof UserIdentity] as unknown) = + defaultIdentity[key as keyof UserIdentity]; + + if (browser) localStorage.setItem('identity', JSON.stringify(updatedIdentity)); + + return updatedIdentity; + }, + setKey: (key: keyof UserIdentity, value: unknown) => + update((identity) => ({ ...identity, [key]: value })) + }; }; const identity = createStore(); identity.subscribe((value) => { - if (browser) localStorage.setItem('identity', JSON.stringify(value)); + if (browser) localStorage.setItem('identity', JSON.stringify(value)); }); export default identity; 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; diff --git a/src/stores/locale.ts b/src/stores/locale.ts index 2105eb51..ae4a5107 100644 --- a/src/stores/locale.ts +++ b/src/stores/locale.ts @@ -5,68 +5,68 @@ import type { Locale } from '$lib/Locale/layout'; 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 48bb8f9a..24bc9ce1 100644 --- a/src/stores/manga.ts +++ b/src/stores/manga.ts @@ -4,7 +4,7 @@ import { writable } from 'svelte/store'; const manga = writable<string>(browser ? localStorage.getItem('manga') ?? '' : ''); manga.subscribe((value) => { - if (browser) localStorage.setItem('manga', value); + if (browser) localStorage.setItem('manga', value); }); export default manga; diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 9d290329..0d96d419 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -8,193 +8,193 @@ import identity from './identity'; const VERSION = '1.0.1'; export interface Settings { - cacheMangaMinutes: number; - cacheMinutes: number; - displayUpcomingAnimeCollapsed: boolean; - displayAnimeCollapsed: boolean; - displayMangaCollapsed: boolean; - displayNotStarted: boolean; - displayUnresolved: boolean; - calculateChaptersRoundedDown: boolean; - displaySortedByDifference: 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; - displayAniListNotifications: boolean; - displayFiltersIncludeCompleted: boolean; - displayDataSaver: boolean; - debugDummyLists: boolean; + cacheMangaMinutes: number; + cacheMinutes: number; + displayUpcomingAnimeCollapsed: boolean; + displayAnimeCollapsed: boolean; + displayMangaCollapsed: boolean; + displayNotStarted: boolean; + displayUnresolved: boolean; + calculateChaptersRoundedDown: boolean; + displaySortedByDifference: 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; + displayAniListNotifications: boolean; + displayFiltersIncludeCompleted: boolean; + displayDataSaver: boolean; + debugDummyLists: 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, - displaySortedByDifference: 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, - displayAniListNotifications: false, - displayFiltersIncludeCompleted: false, - displayDataSaver: 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, + displaySortedByDifference: 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, + displayAniListNotifications: false, + displayFiltersIncludeCompleted: false, + displayDataSaver: 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 { 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, - set, - update, - reset: () => 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[key as keyof Settings] as unknown) = - defaultSettings[key as keyof Settings]; - - if (browser) localStorage.setItem('settings', JSON.stringify(updatedSettings)); - - return updatedSettings; - }, - setKey: (key: keyof Settings, value: unknown) => - update((settings) => ({ ...settings, [key]: value })) - }; + 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, + set, + update, + reset: () => 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[key as keyof Settings] as unknown) = + defaultSettings[key as keyof Settings]; + + if (browser) localStorage.setItem('settings', JSON.stringify(updatedSettings)); + + return updatedSettings; + }, + setKey: (key: keyof Settings, value: unknown) => + update((settings) => ({ ...settings, [key]: value })) + }; }; const settings = createStore(); settings.subscribe((value) => { - if (browser) localStorage.setItem('settings', JSON.stringify(value)); - - 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 = (object1: Settings, object2: Settings) => { - type AnyObject = { [key: string]: unknown }; - - return ( - Object.keys(object1).length === Object.keys(object2).length && - Object.keys(object1).every( - (key) => - (object1 as unknown as AnyObject)[key] == (object2 as unknown as AnyObject)[key] - ) - ); - }; - - if (data && 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) localStorage.setItem('settings', JSON.stringify(value)); + + 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 = (object1: Settings, object2: Settings) => { + type AnyObject = { [key: string]: unknown }; + + return ( + Object.keys(object1).length === Object.keys(object2).length && + Object.keys(object1).every( + (key) => + (object1 as unknown as AnyObject)[key] == (object2 as unknown as AnyObject)[key] + ) + ); + }; + + if (data && 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/settingsSyncTimes.ts b/src/stores/settingsSyncTimes.ts index d9b790d2..8b4d355b 100644 --- a/src/stores/settingsSyncTimes.ts +++ b/src/stores/settingsSyncTimes.ts @@ -1,13 +1,13 @@ 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/tooltipPosition.ts b/src/stores/tooltipPosition.ts index 06b38fe1..ce523210 100644 --- a/src/stores/tooltipPosition.ts +++ b/src/stores/tooltipPosition.ts @@ -2,11 +2,11 @@ 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; |