import Rating from "@components/Rating.svelte"; import { App, Modal } from "obsidian"; import { mount, unmount } from "svelte"; export class RatingModal extends Modal { private component: ReturnType | undefined; constructor(app: App, private readonly onSubmit: (rating: number) => void) { super(app); } onOpen(): void { this.component = mount(Rating, { target: this.contentEl, props: { onSubmit: (rating) => { this.onSubmit(rating); this.close(); }, }, }); } onClose(): void { if (this.component) { unmount(this.component); this.component = undefined; } } static createAndOpen(app: App): Promise { return new Promise((resolve) => { const modal = new RatingModal(app, (rating) => { resolve(rating); }); modal.open(); }); } }