diff --git a/src/main.ts b/src/main.ts index 65589c7..a443f35 100644 --- a/src/main.ts +++ b/src/main.ts @@ -302,7 +302,10 @@ export default class BookTrackerPlugin extends Plugin { return; } - const rating = await RatingModal.createAndOpen(this.app); + const rating = await RatingModal.createAndOpen( + this.app, + this.settings.spiceProperty !== "" + ); await this.readingLog.addEntry( activeFile.basename, @@ -317,6 +320,9 @@ export default class BookTrackerPlugin extends Plugin { frontMatter[this.settings.statusProperty] = READ_STATE; frontMatter[this.settings.endDateProperty] = endDate; frontMatter[this.settings.ratingProperty] = rating; + if (this.settings.spiceProperty !== "") { + frontMatter[this.settings.spiceProperty] = rating; + } }); new Notice("Reading finished for " + activeFile.name); diff --git a/src/ui/components/RatingInput.svelte b/src/ui/components/RatingInput.svelte index 307875f..d2738ad 100644 --- a/src/ui/components/RatingInput.svelte +++ b/src/ui/components/RatingInput.svelte @@ -1,14 +1,26 @@ @@ -62,18 +81,37 @@
+
{#each items as item (item.index)}
{#if item.state === "inactive"} - + {#if inactive} + {@render inactive()} + {:else} + + {/if} {:else if item.state === "active"} - + {#if active} + {@render active()} + {:else} + + {/if} {:else if item.state === "partial"} - - + {#if partial} + {@render partial()} + {:else} + + + {/if} {/if}
{/each} @@ -84,6 +122,10 @@ .rating-input { cursor: pointer; + input { + display: none; + } + .ctrl { position: absolute; z-index: 2; diff --git a/src/ui/modals/RatingModal.ts b/src/ui/modals/RatingModal.ts index 3e1e242..74d1bcd 100644 --- a/src/ui/modals/RatingModal.ts +++ b/src/ui/modals/RatingModal.ts @@ -3,16 +3,27 @@ import { App } from "obsidian"; import { SvelteModal } from "./SvelteModal"; export class RatingModal extends SvelteModal { - constructor(app: App, onSubmit: (rating: number) => void = () => {}) { - super(app, RatingModalView, { props: { onSubmit } }); + constructor( + app: App, + spiceConfigured: boolean, + onSubmit: (rating: number, spice: number) => void = () => {} + ) { + super(app, RatingModalView, { props: { spiceConfigured, onSubmit } }); } - static createAndOpen(app: App): Promise { + static createAndOpen( + app: App, + spiceConfigured: boolean + ): Promise<{ rating: number; spice: number }> { return new Promise((resolve) => { - const modal = new RatingModal(app, (rating) => { - modal.close(); - resolve(rating); - }); + const modal = new RatingModal( + app, + spiceConfigured, + (rating, spice) => { + modal.close(); + resolve({ rating, spice }); + } + ); modal.open(); }); } diff --git a/src/ui/modals/RatingModalView.svelte b/src/ui/modals/RatingModalView.svelte index f668b26..35fb33e 100644 --- a/src/ui/modals/RatingModalView.svelte +++ b/src/ui/modals/RatingModalView.svelte @@ -1,32 +1,53 @@

Rating

-
- - +
+ +
+ {#if spiceConfigured} +
+ + + {#snippet inactive()} + + {/snippet} + {#snippet active()} + + {/snippet} + +
+ {/if}