Refactor stats, add derived catalog stores, improve timer
This commit is contained in:
@@ -49,6 +49,7 @@ export type Settings = {
|
||||
mobile: boolean;
|
||||
backgroundColor: string;
|
||||
swipeThreshold: number;
|
||||
showTimer: boolean;
|
||||
fontSize: FontSize;
|
||||
zoomDefault: ZoomModes;
|
||||
volumeDefaults: VolumeDefaults;
|
||||
@@ -71,6 +72,7 @@ const defaultSettings: Settings = {
|
||||
mobile: false,
|
||||
backgroundColor: '#030712',
|
||||
swipeThreshold: 50,
|
||||
showTimer: false,
|
||||
fontSize: 'auto',
|
||||
zoomDefault: 'zoomFitToScreen',
|
||||
volumeDefaults: {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { browser } from '$app/environment';
|
||||
import { derived, get, writable } from 'svelte/store';
|
||||
import { settings } from './settings';
|
||||
import { zoomDefault } from '$lib/panzoom';
|
||||
import { page } from '$app/stores';
|
||||
import { manga, volume } from '$lib/catalog';
|
||||
|
||||
export type VolumeSettings = {
|
||||
rightToLeft: boolean;
|
||||
@@ -21,6 +23,13 @@ type VolumeData = {
|
||||
settings: VolumeSettings;
|
||||
}
|
||||
|
||||
type TotalStats = {
|
||||
completed: number;
|
||||
pagesRead: number;
|
||||
charsRead: number;
|
||||
minutesRead: number;
|
||||
}
|
||||
|
||||
type Volumes = Record<string, VolumeData>;
|
||||
|
||||
|
||||
@@ -132,4 +141,51 @@ export function updateVolumeSetting(volume: string, key: VolumeSettingsKey, valu
|
||||
};
|
||||
});
|
||||
zoomDefault();
|
||||
}
|
||||
}
|
||||
|
||||
export const totalStats = derived([volumes, page], ([$volumes, $page]) => {
|
||||
if ($page && $volumes) {
|
||||
return Object.values($volumes).reduce<TotalStats>((stats, { chars, completed, timeReadInMinutes, progress }) => {
|
||||
if (completed) {
|
||||
stats.completed++;
|
||||
}
|
||||
|
||||
stats.pagesRead += progress;
|
||||
stats.minutesRead += timeReadInMinutes;
|
||||
stats.charsRead += chars
|
||||
|
||||
return stats;
|
||||
}, {
|
||||
charsRead: 0,
|
||||
completed: 0,
|
||||
pagesRead: 0,
|
||||
minutesRead: 0
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const mangaStats = derived([manga, volumes], ([$manga, $volumes]) => {
|
||||
if ($manga && $volumes) {
|
||||
return $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 }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export const volumeStats = derived([volume, volumes], ([$volume, $volumes]) => {
|
||||
if ($volume && $volumes) {
|
||||
const { chars, completed, timeReadInMinutes, progress } = $volumes[$volume.mokuroData.volume_uuid]
|
||||
return { chars, completed, timeReadInMinutes, progress }
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user