generated from tpl/obsidian-sample-plugin
40 lines
879 B
TypeScript
40 lines
879 B
TypeScript
import GoodreadsSearchModalView from "./GoodreadsSearchModalView.svelte";
|
|
import { Goodreads, type SearchResult } from "@data-sources/Goodreads";
|
|
import { App } from "obsidian";
|
|
import { SvelteModal } from "./SvelteModal";
|
|
|
|
export class GoodreadsSearchModal extends SvelteModal<
|
|
typeof GoodreadsSearchModalView
|
|
> {
|
|
constructor(
|
|
app: App,
|
|
goodreads: Goodreads,
|
|
onSearch: (error: any, results: SearchResult[]) => void = () => {}
|
|
) {
|
|
super(app, GoodreadsSearchModalView, { goodreads, onSearch });
|
|
}
|
|
|
|
static createAndOpen(
|
|
app: App,
|
|
goodreads: Goodreads
|
|
): Promise<SearchResult[]> {
|
|
return new Promise((resolve, reject) => {
|
|
const modal = new GoodreadsSearchModal(
|
|
app,
|
|
goodreads,
|
|
(error, results) => {
|
|
modal.close();
|
|
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
|
|
resolve(results);
|
|
}
|
|
);
|
|
modal.open();
|
|
});
|
|
}
|
|
}
|