diff --git a/src/commands/ResetReadingStatusCommand.ts b/src/commands/ResetReadingStatusCommand.ts index de5c083..690c239 100644 --- a/src/commands/ResetReadingStatusCommand.ts +++ b/src/commands/ResetReadingStatusCommand.ts @@ -43,7 +43,7 @@ export class ResetReadingStatusCommand extends EditorCheckCommand { frontMatter[this.settings.endDateProperty] = ""; }); - this.readingLog.removeEntriesForBook(file.basename); + this.readingLog.deleteEntriesForBook(file.basename); new Notice("Reading status reset for " + file.basename); } diff --git a/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte b/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte index fbfe071..c9750cf 100644 --- a/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte +++ b/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte @@ -1,5 +1,5 @@
@@ -207,6 +226,7 @@ {#each week as day} {@const isThisMonth = day.month() === month} + {@const date = day.date()}
{day.date()} - {#if isThisMonth && bookMap.has(day.date())} - {@const data = bookMap.get(day.date())!} + {#if isThisMonth && date in bookMap} + {@const data = bookMap[date]} Pages: {data.totalPagesRead} {/if}
- {#if isThisMonth && bookMap.has(day.date())} - {@const data = bookMap.get(day.date())!} - {#each data.covers as cover} - {#if cover} - {cover.alt} - {/if} + {#if isThisMonth && date in bookMap} + {@const data = bookMap[date]} + {#each data.books as book} +
+ + {book.coverAlt} + +
{/each} {/if}
@@ -312,59 +334,46 @@ width: 100%; aspect-ratio: 2 / 3; - img { + .cover { border-radius: var(--radius-l); - } + position: absolute; + height: 100%; + width: 100%; - &:has(img:first-child:nth-last-child(1)) { img { - position: absolute; - height: 100%; + border-radius: var(--radius-l); width: 100%; + height: 100%; + object-fit: cover; } } - &:has(img:first-child:nth-last-child(2)) { - img:first-child { - position: absolute; - height: 100%; - width: 100%; + &:has(.cover:first-child:nth-last-child(2)) { + .cover:first-child { clip-path: polygon(0 0, 100% 0, 0 100%); } - img:last-child { - position: absolute; - height: 100%; - width: 100%; + .cover:last-child { clip-path: polygon(100% 100%, 100% 0, 0 100%); } } - &:has(img:first-child:nth-last-child(3)) { - img:first-child { - position: absolute; - height: 100%; - width: 100%; + &:has(.cover:first-child:nth-last-child(3)) { + .cover:first-child { clip-path: polygon(0 0, 100% 0, 100% 20%, 0 50%); } - img:nth-child(2) { - position: absolute; - height: 100%; - width: 100%; + .cover:nth-child(2) { clip-path: polygon(100% 80%, 100% 20%, 0 50%); } - img:last-child { - position: absolute; - height: 100%; - width: 100%; + .cover:last-child { clip-path: polygon(0 50%, 100% 80%, 100% 100%, 0% 100%); } } - &:has(img:first-child:nth-last-child(4)) { - img:first-child { + &:has(.cover:first-child:nth-last-child(4)) { + .cover:first-child { position: absolute; height: 50%; width: 50%; @@ -372,7 +381,7 @@ left: 0; } - img:nth-child(2) { + .cover:nth-child(2) { position: absolute; height: 50%; width: 50%; @@ -380,7 +389,7 @@ right: 0; } - img:nth-child(3) { + .cover:nth-child(3) { position: absolute; height: 50%; width: 50%; @@ -388,7 +397,7 @@ left: 0; } - img:last-child { + .cover:last-child { position: absolute; height: 50%; width: 50%; diff --git a/src/ui/components/OpenFileLink.svelte b/src/ui/components/OpenFileLink.svelte index 5441586..95258ee 100644 --- a/src/ui/components/OpenFileLink.svelte +++ b/src/ui/components/OpenFileLink.svelte @@ -16,8 +16,14 @@ const href = $derived( makeUri(file instanceof TFile ? file.path : getLinkpath(file)), ); + + const title = $derived( + file instanceof TFile + ? file.basename + : file.split("/").pop()?.replace(".md", ""), + ); - + {@render children?.()} diff --git a/src/ui/components/charts/BookAndPages.svelte b/src/ui/components/charts/BookAndPages.svelte index 885d9b0..3a5fa17 100644 --- a/src/ui/components/charts/BookAndPages.svelte +++ b/src/ui/components/charts/BookAndPages.svelte @@ -111,12 +111,13 @@ type: "linear", display: true, position: "left", - ticks: { beginAtZero: true }, + beginAtZero: true, }, y1: { type: "linear", display: !isMonthly, position: "right", + beginAtZero: true, grid: { drawOnChartArea: false }, }, }, diff --git a/src/ui/stores/reading-log.svelte.ts b/src/ui/stores/reading-log.svelte.ts index f5ed19a..7b81d8d 100644 --- a/src/ui/stores/reading-log.svelte.ts +++ b/src/ui/stores/reading-log.svelte.ts @@ -1,6 +1,10 @@ import type { ReadingLog, ReadingLogEntry } from "@utils/ReadingLog"; import { getContext, setContext } from "svelte"; -import { createDateFilter, type DateFilterStore } from "./date-filter.svelte"; +import { + createDateFilter, + type DateFilterStore, + type DateFilterStoreOptions, +} from "./date-filter.svelte"; export interface ReadingLogStore extends DateFilterStore { get entries(): ReadingLogEntry[]; @@ -12,13 +16,16 @@ export interface ReadingLogStore extends DateFilterStore { destroy(): void; } -export function createReadingLog(readingLog: ReadingLog): ReadingLogStore { +export function createReadingLog( + readingLog: ReadingLog, + { initialMonth = true, ...otherOpts }: DateFilterStoreOptions = {} +): ReadingLogStore { let entries: ReadingLogEntry[] = $state(readingLog.getEntries()); const dateFilter = createDateFilter( () => entries, (entry) => entry.createdAt, - { initialMonth: true } + { initialMonth, ...otherOpts } ); async function addEntry(entry: ReadingLogEntry): Promise { @@ -34,18 +41,24 @@ export function createReadingLog(readingLog: ReadingLog): ReadingLogStore { } async function removeEntry(entry: ReadingLogEntry): Promise { - await readingLog.removeEntry(entry); + await readingLog.deleteEntry(entry); } const loadHandler = readingLog.on("load", (payload) => { + console.info("Reading log loaded"); + console.debug("Reading log entries:", payload.entries); entries = payload.entries; }); - const createdHandler = readingLog.on("created", (payload) => { + const createdHandler = readingLog.on("create", (payload) => { + console.info("Reading log entry created"); + console.debug("Reading log entry:", payload.entry); entries.push(payload.entry); }); - const updatedHandler = readingLog.on("updated", (payload) => { + const updatedHandler = readingLog.on("update", (payload) => { + console.info("Reading log entry updated"); + console.debug("Reading log entry:", payload.entry); const index = entries.findIndex( (entry) => entry.id === payload.entry.id ); @@ -54,7 +67,9 @@ export function createReadingLog(readingLog: ReadingLog): ReadingLogStore { } }); - const removedHandler = readingLog.on("removed", (payload) => { + const removedHandler = readingLog.on("delete", (payload) => { + console.info("Reading log entry deleted"); + console.debug("Reading log entry:", payload.entry); const index = entries.findIndex( (entry) => entry.id === payload.entry.id ); diff --git a/src/utils/ReadingLog.ts b/src/utils/ReadingLog.ts index a9fd71f..3e9b4e1 100644 --- a/src/utils/ReadingLog.ts +++ b/src/utils/ReadingLog.ts @@ -14,9 +14,9 @@ export interface ReadingLogEntry { interface ReadingLogEventMap { load: { entries: ReadingLogEntry[] }; - created: { entry: ReadingLogEntry }; - updated: { entry: ReadingLogEntry }; - removed: { entry: ReadingLogEntry }; + create: { entry: ReadingLogEntry }; + update: { entry: ReadingLogEntry }; + delete: { entry: ReadingLogEntry }; } const DEFAULT_FILENAME = "reading-log.json"; @@ -126,7 +126,7 @@ export class ReadingLog extends EventEmitter { public async addRawEntry(entry: ReadingLogEntry) { this.entries.push(entry); await this.save(); - this.emit("created", { entry }); + this.emit("create", { entry }); } public async updateEntry(entry: ReadingLogEntry): Promise { @@ -138,20 +138,20 @@ export class ReadingLog extends EventEmitter { this.entries[index] = entry; await this.save(); - this.emit("updated", { entry }); + this.emit("update", { entry }); } - public async removeEntry(entry: ReadingLogEntry): Promise { + public async deleteEntry(entry: ReadingLogEntry): Promise { const index = this.entries.findIndex((other) => other.id === entry.id); if (index !== -1) { const removed = this.entries.splice(index, 1); await this.save(); - this.emit("removed", { entry: removed[0] }); + this.emit("delete", { entry: removed[0] }); } } - public async removeEntriesForBook(book: string): Promise { + public async deleteEntriesForBook(book: string): Promise { this.entries = this.entries.filter((entry) => entry.book !== book); await this.save(); }