From 791fa96d19123b0e5816ef7fa92ed046bd3a49d9 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Fri, 18 Jul 2025 23:14:05 -0400 Subject: [PATCH] Change how book covers are styled --- .../AToZChallengeCodeBlockView.svelte | 11 +-- .../ReadingCalendarCodeBlockView.svelte | 14 +-- src/ui/code-blocks/ShelfCodeBlockView.svelte | 15 ++- src/ui/components/BookCover.svelte | 91 +++++++++++++++++-- src/ui/components/BookshelfView.svelte | 12 +-- src/ui/components/DetailsView.svelte | 33 ++++--- src/ui/components/TableView.svelte | 10 +- .../components/setting/FileSuggestItem.svelte | 6 +- .../setting/FolderSuggestItem.svelte | 6 +- .../setting/PropertySuggestItem.svelte | 5 +- .../components/suggesters/FileSuggest.svelte | 6 +- .../suggesters/FolderSuggest.svelte | 6 +- .../suggesters/PropertySuggest.svelte | 6 +- src/ui/modals/GoodreadsSearchModal.ts | 2 +- src/ui/modals/GoodreadsSearchModalView.svelte | 6 +- src/ui/modals/GoodreadsSearchSuggestModal.ts | 2 +- .../modals/GoodreadsSearchSuggestion.svelte | 6 +- src/ui/modals/RatingModal.ts | 2 +- src/ui/modals/RatingModalView.svelte | 6 +- .../ReadingLogEntryEditModalView.svelte | 3 +- src/ui/modals/ReadingProgressModal.ts | 2 +- src/ui/modals/ReadingProgressModalView.svelte | 7 +- .../settings/BookTrackerSettingTabView.svelte | 9 +- src/ui/stores/date-filter.svelte.ts | 10 +- 24 files changed, 186 insertions(+), 90 deletions(-) diff --git a/src/ui/code-blocks/AToZChallengeCodeBlockView.svelte b/src/ui/code-blocks/AToZChallengeCodeBlockView.svelte index c437bef..6080dfd 100644 --- a/src/ui/code-blocks/AToZChallengeCodeBlockView.svelte +++ b/src/ui/code-blocks/AToZChallengeCodeBlockView.svelte @@ -12,8 +12,10 @@ import OpenFileLink from "@ui/components/OpenFileLink.svelte"; import DateFilter from "@ui/components/DateFilter.svelte"; import BookCover from "@ui/components/BookCover.svelte"; + import { setAppContext } from "@ui/stores/app"; const { plugin }: SvelteCodeBlockProps = $props(); + setAppContext(plugin.app); const settingsStore = createSettings(plugin); setSettingsContext(settingsStore); @@ -88,7 +90,7 @@ {#if metadata[letter]} {@const meta = metadata[letter]} - + {:else}
{letter}
@@ -139,13 +141,6 @@ font-weight: bold; font-style: italic; } - - :global(img) { - width: 100%; - height: 100%; - object-fit: cover; - border-radius: var(--radius-l); - } } } } diff --git a/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte b/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte index acc36b9..3ddaef9 100644 --- a/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte +++ b/src/ui/code-blocks/ReadingCalendarCodeBlockView.svelte @@ -19,8 +19,10 @@ import OpenFileLink from "@ui/components/OpenFileLink.svelte"; import moment from "@external/moment"; import BookCover from "@ui/components/BookCover.svelte"; + import { setAppContext } from "@ui/stores/app"; const { plugin }: SvelteCodeBlockProps = $props(); + setAppContext(plugin.app); const settingsStore = createSettings(plugin); setSettingsContext(settingsStore); @@ -228,8 +230,8 @@
@@ -298,6 +300,7 @@ display: flex; justify-content: space-between; align-items: center; + margin-bottom: -12px; .total-pages-read { font-size: var(--font-smallest); @@ -322,15 +325,6 @@ width: 100%; height: 100%; } - - :global(img) { - border-radius: var(--radius-l); - width: 100%; - height: 100%; - min-width: 100%; - min-height: 100%; - object-fit: cover; - } } &:has(.cover:first-child:nth-last-child(2)) { diff --git a/src/ui/code-blocks/ShelfCodeBlockView.svelte b/src/ui/code-blocks/ShelfCodeBlockView.svelte index 29377eb..7113bb2 100644 --- a/src/ui/code-blocks/ShelfCodeBlockView.svelte +++ b/src/ui/code-blocks/ShelfCodeBlockView.svelte @@ -17,6 +17,10 @@ import DetailsView from "@ui/components/DetailsView.svelte"; import { setAppContext } from "@ui/stores/app"; import type { SvelteCodeBlockProps } from "./SvelteCodeBlockRenderer"; + import { + createReadingLog, + setReadingLogContext, + } from "@ui/stores/reading-log.svelte"; const { plugin, source }: SvelteCodeBlockProps = $props(); setAppContext(plugin.app); @@ -32,6 +36,11 @@ }); setMetadataContext(metadataStore); + const readingLog = createReadingLog(plugin.readingLog, { + disableAllFiltering: true, + }); + setReadingLogContext(readingLog); + let view = $state(settings.defaultView); onDestroy(() => metadataStore.destroy()); @@ -54,11 +63,11 @@ {/if} {#if view === "bookshelf"} - + {:else if view === "table"} - + {:else if view === "details"} - + {/if} diff --git a/src/ui/components/BookCover.svelte b/src/ui/components/BookCover.svelte index 6814d69..5fb25e1 100644 --- a/src/ui/components/BookCover.svelte +++ b/src/ui/components/BookCover.svelte @@ -1,14 +1,49 @@ -{coverAlt} +
+ {coverAlt} +
diff --git a/src/ui/components/BookshelfView.svelte b/src/ui/components/BookshelfView.svelte index a00dcb8..0400592 100644 --- a/src/ui/components/BookshelfView.svelte +++ b/src/ui/components/BookshelfView.svelte @@ -12,10 +12,7 @@ import { v4 as uuidv4 } from "uuid"; import memoize from "just-memoize"; import type { TFile } from "obsidian"; - - interface Props { - plugin: BookTrackerPlugin; - } + import { getAppContext } from "@ui/stores/app"; interface BookData { id: string; @@ -34,7 +31,7 @@ books: BookData[]; } - const { plugin }: Props = $props(); + const app = getAppContext(); const metadataStore = getMetadataContext(); @@ -128,7 +125,7 @@ design={bookData.design} orientation="flat" onClick={() => - plugin.app.workspace + app.workspace .getLeaf(false) .openFile(bookData.file)} /> @@ -143,8 +140,7 @@ color={book.color} design={book.design} orientation={book.orientation} - onClick={() => - plugin.app.workspace.getLeaf(false).openFile(book.file)} + onClick={() => app.workspace.getLeaf(false).openFile(book.file)} /> {/if} {/each} diff --git a/src/ui/components/DetailsView.svelte b/src/ui/components/DetailsView.svelte index 95064b6..5a7bca1 100644 --- a/src/ui/components/DetailsView.svelte +++ b/src/ui/components/DetailsView.svelte @@ -1,27 +1,27 @@
{#each metadataStore.metadata as meta}
- +

@@ -59,11 +59,18 @@

{/if} {#if settings.statusFilter === STATUS_IN_PROGRESS} + {@const logEntryIndex = + readingLog.entries.findLastIndex( + (e) => e.book === meta.file.basename, + )} + {@const logEntry = + logEntryIndex !== -1 + ? readingLog.entries[logEntryIndex] + : null} +

- Current Page: {plugin.readingLog.getLastEntryForBook( - meta.file.basename, - )?.pagesReadTotal ?? 0} + Current Page: {logEntry?.pagesReadTotal ?? 0}

{/if} {#if settings.statusFilter === STATUS_READ} @@ -144,16 +151,20 @@ background-color: var(--background-secondary); border-radius: var(--radius-l); - :global(img) { - border-radius: var(--radius-l); + :global(.book-cover) { + width: 100%; + height: auto; + max-height: 100%; max-width: 30%; } - @container (width < 600px) { + @container (width < 700px) { flex-direction: column; align-items: center; - :global(img) { + :global(.book-cover) { + height: 100%; + width: auto; max-height: 30rem; max-width: 100%; } diff --git a/src/ui/components/TableView.svelte b/src/ui/components/TableView.svelte index 098db6d..cea1e04 100644 --- a/src/ui/components/TableView.svelte +++ b/src/ui/components/TableView.svelte @@ -1,6 +1,5 @@ @@ -38,7 +36,7 @@ {#each metadataStore.metadata as meta} - + @@ -96,6 +94,10 @@ &.cover { padding: 0; margin: 0; + + :global(.book-cover) { + margin: 0 auto; + } } } } diff --git a/src/ui/components/setting/FileSuggestItem.svelte b/src/ui/components/setting/FileSuggestItem.svelte index bf41573..32b04cd 100644 --- a/src/ui/components/setting/FileSuggestItem.svelte +++ b/src/ui/components/setting/FileSuggestItem.svelte @@ -1,20 +1,18 @@ {#snippet control()} - + {/snippet} diff --git a/src/ui/components/setting/FolderSuggestItem.svelte b/src/ui/components/setting/FolderSuggestItem.svelte index ac96c24..767cf36 100644 --- a/src/ui/components/setting/FolderSuggestItem.svelte +++ b/src/ui/components/setting/FolderSuggestItem.svelte @@ -1,20 +1,18 @@ {#snippet control()} - + {/snippet} diff --git a/src/ui/components/setting/PropertySuggestItem.svelte b/src/ui/components/setting/PropertySuggestItem.svelte index e811f3f..f5a09a8 100644 --- a/src/ui/components/setting/PropertySuggestItem.svelte +++ b/src/ui/components/setting/PropertySuggestItem.svelte @@ -1,18 +1,15 @@
diff --git a/src/ui/modals/RatingModal.ts b/src/ui/modals/RatingModal.ts index 32d4776..b0b276f 100644 --- a/src/ui/modals/RatingModal.ts +++ b/src/ui/modals/RatingModal.ts @@ -8,7 +8,7 @@ export class RatingModal extends SvelteModal { spiceConfigured: boolean, onSubmit: (rating: number, spice: number) => void = () => {} ) { - super(app, RatingModalView, { spiceConfigured, onSubmit }); + super(app, RatingModalView, { app, spiceConfigured, onSubmit }); } static createAndOpen( diff --git a/src/ui/modals/RatingModalView.svelte b/src/ui/modals/RatingModalView.svelte index 2785ff0..ef3df06 100644 --- a/src/ui/modals/RatingModalView.svelte +++ b/src/ui/modals/RatingModalView.svelte @@ -1,12 +1,16 @@