From 217f66acf9ab8228544aa8a8d82dd591ca0bca26 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Mon, 30 Jun 2025 10:29:41 -0400 Subject: [PATCH] Add book folder setting to improve book suggester filtering --- src/ui/code-blocks/ReadingLogCodeBlock.ts | 7 +--- .../ReadingLogCodeBlockView.svelte | 24 ++++++------- .../components/suggesters/BookSuggest.svelte | 9 +++-- src/ui/modals/ReadingLogEntryEditModal.ts | 8 ++--- .../ReadingLogEntryEditModalView.svelte | 13 ++++--- .../settings/BookTrackerSettingTabView.svelte | 34 +++++++++++++------ src/ui/settings/types.ts | 4 +++ 7 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/ui/code-blocks/ReadingLogCodeBlock.ts b/src/ui/code-blocks/ReadingLogCodeBlock.ts index cb099ae..54e013b 100644 --- a/src/ui/code-blocks/ReadingLogCodeBlock.ts +++ b/src/ui/code-blocks/ReadingLogCodeBlock.ts @@ -17,12 +17,7 @@ export class ReadingLogCodeBlockRenderer extends SvelteCodeBlockRenderer< typeof ReadingLogCodeBlockView > { constructor(contentEl: HTMLElement, plugin: BookTrackerPlugin) { - super(contentEl, ReadingLogCodeBlockView, { - props: { - app: plugin.app, - readingLog: plugin.readingLog, - }, - }); + super(contentEl, ReadingLogCodeBlockView, { props: { plugin } }); } onunload() {} diff --git a/src/ui/code-blocks/ReadingLogCodeBlockView.svelte b/src/ui/code-blocks/ReadingLogCodeBlockView.svelte index 228f2dc..09a6765 100644 --- a/src/ui/code-blocks/ReadingLogCodeBlockView.svelte +++ b/src/ui/code-blocks/ReadingLogCodeBlockView.svelte @@ -1,21 +1,19 @@ diff --git a/src/ui/components/suggesters/BookSuggest.svelte b/src/ui/components/suggesters/BookSuggest.svelte index 7b4f6ea..61fa01d 100644 --- a/src/ui/components/suggesters/BookSuggest.svelte +++ b/src/ui/components/suggesters/BookSuggest.svelte @@ -7,6 +7,7 @@ id: string; asString?: boolean; value?: TFile | string; + bookFolder?: string; onSelected?: (fileOrPath: TFile | string) => void; }; @@ -15,6 +16,7 @@ id, asString, value = $bindable(), + bookFolder, onSelected, }: Props = $props(); @@ -23,8 +25,11 @@ function handleChange(query: string) { items = app.vault .getMarkdownFiles() - .filter((f) => - f.basename.toLowerCase().includes(query.toLowerCase()), + .filter( + (f) => + (bookFolder === undefined || + f.path.startsWith(bookFolder)) && + f.basename.toLowerCase().includes(query.toLowerCase()), ) .map((f) => ({ text: f.basename, diff --git a/src/ui/modals/ReadingLogEntryEditModal.ts b/src/ui/modals/ReadingLogEntryEditModal.ts index 295dba1..88b40e8 100644 --- a/src/ui/modals/ReadingLogEntryEditModal.ts +++ b/src/ui/modals/ReadingLogEntryEditModal.ts @@ -1,18 +1,18 @@ import ReadingLogEntryEditModalView from "./ReadingLogEntryEditModalView.svelte"; import type { ReadingLogEntry } from "@src/types"; -import { App } from "obsidian"; import { SvelteModal } from "./SvelteModal"; +import type BookTrackerPlugin from "@src/main"; export class ReadingLogEntryEditModal extends SvelteModal< typeof ReadingLogEntryEditModalView > { constructor( - app: App, + plugin: BookTrackerPlugin, onSubmit?: (entry: ReadingLogEntry) => void, entry?: ReadingLogEntry ) { - super(app, ReadingLogEntryEditModalView, { - props: { app, entry, onSubmit }, + super(plugin.app, ReadingLogEntryEditModalView, { + props: { plugin, entry, onSubmit }, }); } } diff --git a/src/ui/modals/ReadingLogEntryEditModalView.svelte b/src/ui/modals/ReadingLogEntryEditModalView.svelte index bfc5e83..0a20718 100644 --- a/src/ui/modals/ReadingLogEntryEditModalView.svelte +++ b/src/ui/modals/ReadingLogEntryEditModalView.svelte @@ -1,14 +1,14 @@
+
+ +
@@ -79,7 +93,7 @@ {app} id="status-field" name="Status Field" - description="Select the folder to use for To Be Read entries" + description="Select the folder to use for To Be Read entries." bind:value={$settings.statusProperty} accepts={["text"]} /> @@ -87,7 +101,7 @@ {app} id="start-date-field" name="Start Date Field" - description="Select the field to use for start date" + description="Select the field to use for start date." bind:value={$settings.startDateProperty} accepts={["date"]} /> @@ -95,7 +109,7 @@ {app} id="end-date-field" name="End Date Field" - description="Select the field to use for end date" + description="Select the field to use for end date." bind:value={$settings.endDateProperty} accepts={["date"]} /> @@ -103,7 +117,7 @@ {app} id="rating-field" name="Rating Field" - description="Select the field to use for rating" + description="Select the field to use for rating." bind:value={$settings.ratingProperty} accepts={["number"]} /> @@ -111,7 +125,7 @@ {app} id="page-count-field" name="Page Count Field" - description="Select the field to use for page count" + description="Select the field to use for page count." bind:value={$settings.pageCountProperty} accepts={["number"]} /> diff --git a/src/ui/settings/types.ts b/src/ui/settings/types.ts index 9f9b78a..3e64ace 100644 --- a/src/ui/settings/types.ts +++ b/src/ui/settings/types.ts @@ -1,4 +1,6 @@ export interface BookTrackerSettings { + bookFolder: string; + organizeReadBooks: boolean; templateFile: string; tbrFolder: string; fileNameFormat: string; @@ -14,6 +16,8 @@ export interface BookTrackerSettings { } export const DEFAULT_SETTINGS: BookTrackerSettings = { + bookFolder: "books", + organizeReadBooks: true, templateFile: "", tbrFolder: "books/tbr", fileNameFormat: "{{title}} - {{authors}}",