Refactor stats, add derived catalog stores, improve timer
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user