-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal-search-results.ts
46 lines (42 loc) · 1.83 KB
/
modal-search-results.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { truncate250, WriteMediaToFile } from "fun"
import { IMediaSearchResult, MediaType, MovieManagerSettings } from "interfaces"
import { ConfirmModal } from "modal-confirm"
import { SuggestModal, App } from "obsidian"
export class SearchResultModal extends SuggestModal<IMediaSearchResult> {
mediaResults: IMediaSearchResult[]
settings: MovieManagerSettings
mediaType: MediaType
constructor(app: App, mediaResults: IMediaSearchResult[], settings: MovieManagerSettings, mediaType: MediaType) {
super(app)
this.mediaResults = mediaResults
this.settings = settings
this.mediaType = mediaType
this.inputEl.focus()
}
getSuggestions(query: string): IMediaSearchResult[] {
return this.mediaResults.filter((media) =>
media.title.toLowerCase().includes(query.toLowerCase()))
}
// Renders each suggestion item.
renderSuggestion(media: IMediaSearchResult, el: HTMLElement) {
const container = el.createEl("div", { cls: "search-results-title-container" })
const left = el.createEl("div", { cls: "search-results-poster-container" })
const right = el.createEl("div", { cls: "search-results-overview-container" })
container.createEl("div", { text: media.title, cls: "search-results-title" })
left.createEl("img", { attr:{"src": media.posterUrl, "width":"50"}})
right.createEl("small", { text: truncate250(media.overview) })
}
// Perform action on the selected suggestion.
async onChooseSuggestion(media: IMediaSearchResult, evt: MouseEvent | KeyboardEvent) {
this.settings.formatList = [""]
if (this.settings.showOwnedFormats) {
new ConfirmModal(this.app, this.settings, async (fmtList) => {
let formatList = fmtList.split(",")
this.settings.formatList = formatList
await WriteMediaToFile(media, this.mediaType, this.settings)
}).open()
} else {
await WriteMediaToFile(media, this.mediaType, this.settings)
}
}
}