generated from tpl/obsidian-sample-plugin
Update pages read total when book is selected in reading log entry edit modal view
This commit is contained in:
parent
25e980eff1
commit
649b35f16c
|
@ -11,6 +11,10 @@
|
|||
} from "@ui/stores/settings.svelte";
|
||||
import moment from "@external/moment";
|
||||
import { setAppContext } from "@ui/stores/app";
|
||||
import {
|
||||
createReadingLog,
|
||||
setReadingLogContext,
|
||||
} from "@ui/stores/reading-log.svelte";
|
||||
|
||||
const INPUT_DATETIME_FORMAT = "YYYY-MM-DDTHH:mm";
|
||||
|
||||
|
@ -26,17 +30,28 @@
|
|||
const settingsStore = createSettings(plugin);
|
||||
setSettingsContext(settingsStore);
|
||||
|
||||
const readingLogStore = createReadingLog(plugin.readingLog);
|
||||
setReadingLogContext(readingLogStore);
|
||||
|
||||
const metadataStore = createMetadata(plugin, {
|
||||
statusFilter: null,
|
||||
});
|
||||
|
||||
let editMode = $derived(entry !== undefined);
|
||||
const editMode = $derived(entry !== undefined);
|
||||
let book = $state(entry?.book ?? "");
|
||||
let bookMetadata = $derived(
|
||||
const bookMetadata = $derived(
|
||||
metadataStore.metadata.find((m) => m.file.basename === book),
|
||||
);
|
||||
const lastEntryIndex = $derived(
|
||||
readingLogStore.entries.findLastIndex((e) => e.book === book),
|
||||
);
|
||||
const lastEntry = $derived(
|
||||
lastEntryIndex !== -1 ? readingLogStore.entries[lastEntryIndex] : null,
|
||||
);
|
||||
|
||||
const pageCount = $derived(bookMetadata?.book.pageCount ?? 0);
|
||||
let pagesRead = $state(entry?.pagesRead ?? 0);
|
||||
let pagesReadPrev = createPrevious(() => pagesRead);
|
||||
const pagesReadPrev = createPrevious(() => pagesRead);
|
||||
let pagesReadTotal = $state(entry?.pagesReadTotal ?? 0);
|
||||
let pagesRemaining = $state(entry?.pagesRemaining ?? 0);
|
||||
let createdAt = $state(
|
||||
|
@ -44,6 +59,10 @@
|
|||
moment().format(INPUT_DATETIME_FORMAT),
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
pagesReadTotal = (lastEntry?.pagesReadTotal ?? 0) + pagesRead;
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
const diff = pagesRead - (pagesReadPrev.value ?? 0);
|
||||
pagesRead = pagesRead;
|
||||
|
@ -51,7 +70,7 @@
|
|||
});
|
||||
|
||||
$effect(() => {
|
||||
pagesRemaining = (bookMetadata?.book.pageCount ?? 0) - pagesReadTotal;
|
||||
pagesRemaining = pageCount - pagesReadTotal;
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
|
|
Loading…
Reference in New Issue