Refactor stats, add derived catalog stores, improve timer

This commit is contained in:
ZXY101
2024-02-05 15:39:22 +02:00
parent 2e28843a07
commit 1c92a749be
8 changed files with 162 additions and 46 deletions

View File

@@ -1,4 +1,30 @@
import { db } from '$lib/catalog/db';
import { page } from '$app/stores';
import { db, type Catalog } from '$lib/catalog/db';
import type { Volume } from '$lib/types';
import { liveQuery } from 'dexie';
import { derived, type Readable } from 'svelte/store';
export const catalog = liveQuery(() => db.catalog.toArray());
function sortManga(a: Volume, b: Volume) {
if (a.volumeName < b.volumeName) {
return -1;
}
if (a.volumeName > b.volumeName) {
return 1;
}
return 0;
}
export const manga = derived([page, catalog as unknown as Readable<Catalog[]>], ([$page, $catalog]) => {
if ($page && $catalog) {
return $catalog.find((item) => item.id === $page.params.manga)?.manga.sort(sortManga)
}
});
export const volume = derived(([page, manga]), ([$page, $manga]) => {
if ($page && $manga) {
return $manga.find((item) => item.mokuroData.volume_uuid === $page.params.volume)
}
})