series for MAL

This commit is contained in:
mProjectsCode 2022-05-09 16:52:17 +02:00
parent c7a75ff93c
commit ac82168740
8 changed files with 101 additions and 80 deletions

View file

@ -31,7 +31,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
console.log(this.selectedApis);
if (!this.query || this.query.length < 5) {
new Notice("MDB: Query to short");
new Notice('MDB: Query to short');
return;
}
@ -43,7 +43,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
}
if (selectedAPICount === 0) {
new Notice("MDB: No API selected");
new Notice('MDB: No API selected');
return;
}

View file

@ -1,65 +0,0 @@
import {App, SuggestModal} from 'obsidian';
import {APIManager} from '../api/APIManager';
import {MediaTypeModel} from '../models/MediaTypeModel';
export class MediaDbSearchModal extends SuggestModal<MediaTypeModel> {
query: string;
isBusy: boolean;
apiManager: APIManager;
onChoose: (err: Error, result?: MediaTypeModel) => void;
constructor(app: App, apiManager: APIManager, onChoose?: (err: Error, result?: MediaTypeModel) => void) {
super(app);
this.apiManager = apiManager;
this.onChoose = onChoose;
this.isBusy = false;
}
async search(force: boolean = false): Promise<MediaTypeModel[]> {
if (!this.query) {
return;
}
if (!this.isBusy || force) {
this.isBusy = true;
const thisQuery: string = this.query;
console.log('MDB | query started with ' + thisQuery);
const res = await this.apiManager.query(thisQuery);
// console.log(res)
await sleep(1000);
if (this.query === thisQuery) {
this.isBusy = false;
return res;
// return [
// {title: thisQuery, type: 'movie', data: null} as APIRequestResult,
// {title: 'test2', type: 'series', data: {episodes: 24}} as APIRequestResult,
// ];
} else {
return await this.search(true);
}
}
}
async getSuggestions(query: string): Promise<MediaTypeModel[]> {
this.query = query;
return await this.search();
}
renderSuggestion(item: MediaTypeModel, el: HTMLElement): void {
el.createEl('div', {text: item.title});
el.createEl('small', {text: item.type});
}
onChooseSuggestion(item: MediaTypeModel, evt: MouseEvent | KeyboardEvent): void {
this.onChoose(null, item);
}
}

View file

@ -20,8 +20,8 @@ export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
// Renders each suggestion item.
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
el.createEl('div', {text: item.premiere ? `${item.title} (${item.premiere})` : `${item.title}`});
el.createEl('small', {text: `${item.type} from ${item.dataSource}`});
el.createEl('div', {text: item.getFileName()});
el.createEl('small', {text: `${item.type.toUpperCase()} from ${item.dataSource}`});
}
// Perform action on the selected suggestion.