New Search Modal
This commit is contained in:
parent
cc2962220e
commit
6dc813a14c
9 changed files with 203 additions and 28 deletions
31
src/modals/MediaDbSearchResultModal.ts
Normal file
31
src/modals/MediaDbSearchResultModal.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {App, SuggestModal} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
|
||||
export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
|
||||
suggestion: MediaTypeModel[];
|
||||
onChoose: (error: Error, result?: MediaTypeModel) => void;
|
||||
|
||||
constructor(app: App, suggestion: MediaTypeModel[], onChoose: (error: Error, result?: MediaTypeModel) => void) {
|
||||
super(app);
|
||||
this.suggestion = suggestion;
|
||||
this.onChoose = onChoose;
|
||||
}
|
||||
|
||||
getSuggestions(query: string): MediaTypeModel[] {
|
||||
return this.suggestion.filter(item => {
|
||||
const searchQuery = query.toLowerCase();
|
||||
return item.title.toLowerCase().includes(searchQuery);
|
||||
});
|
||||
}
|
||||
|
||||
// Renders each suggestion item.
|
||||
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
|
||||
el.createEl('div', {text: item.title});
|
||||
el.createEl('small', {text: `${item.type} from ${item.dataSource}`});
|
||||
}
|
||||
|
||||
// Perform action on the selected suggestion.
|
||||
onChooseSuggestion(item: MediaTypeModel, evt: MouseEvent | KeyboardEvent) {
|
||||
this.onChoose(null, item);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue