generated from tpl/obsidian-sample-plugin
40 lines
821 B
TypeScript
40 lines
821 B
TypeScript
import Rating from "@components/Rating.svelte";
|
|
import { App, Modal } from "obsidian";
|
|
import { mount, unmount } from "svelte";
|
|
|
|
export class RatingModal extends Modal {
|
|
private component: ReturnType<typeof Rating> | 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<number> {
|
|
return new Promise((resolve) => {
|
|
const modal = new RatingModal(app, (rating) => {
|
|
resolve(rating);
|
|
});
|
|
modal.open();
|
|
});
|
|
}
|
|
}
|