diff --git a/src/lib/components/Reader/MangaPage.svelte b/src/lib/components/Reader/MangaPage.svelte index c0216e9..704e269 100644 --- a/src/lib/components/Reader/MangaPage.svelte +++ b/src/lib/components/Reader/MangaPage.svelte @@ -1,11 +1,17 @@
1 && !volumeSettings.singlePageView) { - page--; - } - } - } - function onInputClick(this: any) { this.select(); } @@ -117,10 +105,6 @@ changePage(manualPage, true); } - afterUpdate(() => { - zoomDefault(); - }); - function handleShortcuts(event: KeyboardEvent & { currentTarget: EventTarget & Window }) { const action = event.code || event.key; diff --git a/src/lib/components/Settings/Stats.svelte b/src/lib/components/Settings/Stats.svelte index 5b43ccc..e6cf4bb 100644 --- a/src/lib/components/Settings/Stats.svelte +++ b/src/lib/components/Settings/Stats.svelte @@ -24,6 +24,13 @@ return total; }, 0) : 0; + + $: minutesRead = $volumes + ? Object.values($volumes).reduce((total: number, { timeReadInMinutes }) => { + total += timeReadInMinutes; + return total; + }, 0) + : 0; @@ -32,5 +39,6 @@

Completed volumes: {completed}

Pages read: {pagesRead}

Characters read: {charsRead}

+

Minutes read: {minutesRead}

diff --git a/src/lib/components/Settings/Volume/VolumeSettings.svelte b/src/lib/components/Settings/Volume/VolumeSettings.svelte index 0196e69..be12206 100644 --- a/src/lib/components/Settings/Volume/VolumeSettings.svelte +++ b/src/lib/components/Settings/Volume/VolumeSettings.svelte @@ -1,9 +1,17 @@ @@ -18,11 +35,7 @@
These settings only apply to this volume {#each toggles as { key, text, value }} - updateVolumeSetting($page.params.volume, key, !value)}>{text} + onChange(key, value)}>{text} {/each}
diff --git a/src/lib/settings/volume-data.ts b/src/lib/settings/volume-data.ts index 3cadbb3..8986980 100644 --- a/src/lib/settings/volume-data.ts +++ b/src/lib/settings/volume-data.ts @@ -16,8 +16,9 @@ type Progress = Record | undefined; type VolumeData = { progress: number; chars: number; - settings: VolumeSettings; completed: boolean; + timeReadInMinutes: number, + settings: VolumeSettings; } type Volumes = Record; @@ -37,6 +38,7 @@ export function initializeVolume(volume: string) { chars: 0, completed: false, progress: 0, + timeReadInMinutes: 0, settings: { hasCover, rightToLeft, @@ -58,20 +60,34 @@ export function clearVolumes() { volumes.set({}); } -export function updateProgress(volume: string, progress: number, chars: number, completed = false) { +export function updateProgress(volume: string, progress: number, chars?: number, completed = false) { volumes.update((prev) => { return { ...prev, [volume]: { ...prev?.[volume], progress, - chars, + chars: chars || prev?.[volume].chars, completed } }; }); } +export function startCount(volume: string) { + return setInterval(() => { + volumes.update((prev) => { + return { + ...prev, + [volume]: { + ...prev?.[volume], + timeReadInMinutes: prev?.[volume].timeReadInMinutes + 1 + } + }; + }); + }, 60 * 1000) +} + volumes.subscribe((volumes) => { if (browser) { window.localStorage.setItem('volumes', volumes ? JSON.stringify(volumes) : ''); diff --git a/src/routes/[manga]/+page.svelte b/src/routes/[manga]/+page.svelte index 8e71653..1297a9c 100644 --- a/src/routes/[manga]/+page.svelte +++ b/src/routes/[manga]/+page.svelte @@ -7,7 +7,7 @@ import { promptConfirmation } from '$lib/util'; import { page } from '$app/stores'; import type { Volume } from '$lib/types'; - import { deleteVolume } from '$lib/settings'; + import { deleteVolume, volumes } from '$lib/settings'; function sortManga(a: Volume, b: Volume) { if (a.volumeName < b.volumeName) { @@ -21,6 +21,23 @@ $: manga = $catalog?.find((item) => item.id === $page.params.manga)?.manga.sort(sortManga); + $: stats = manga + ?.map((vol) => vol.mokuroData.volume_uuid) + ?.reduce( + (stats: any, volumeId) => { + const timeReadInMinutes = $volumes[volumeId]?.timeReadInMinutes || 0; + const chars = $volumes[volumeId]?.chars || 0; + const completed = $volumes[volumeId]?.completed || 0; + + stats.timeReadInMinutes = stats.timeReadInMinutes + timeReadInMinutes; + stats.chars = stats.chars + chars; + stats.completed = stats.completed + completed; + + return stats; + }, + { timeReadInMinutes: 0, chars: 0, completed: 0 } + ); + async function confirmDelete() { const title = manga?.[0].mokuroData.title_uuid; manga?.forEach((vol) => { @@ -43,11 +60,17 @@ {#if manga}
-
+

{manga[0].mokuroData.title}

-

Volumes: {manga.length}

+
+

Volumes: {stats.completed} / {manga.length}

+

Characters read: {stats.chars}

+

Minutes read: {stats.timeReadInMinutes}

+
+
+
+
-
diff --git a/src/routes/[manga]/[volume]/+page.svelte b/src/routes/[manga]/[volume]/+page.svelte index 74e3048..ca6ac34 100644 --- a/src/routes/[manga]/[volume]/+page.svelte +++ b/src/routes/[manga]/[volume]/+page.svelte @@ -1,7 +1,7 @@