From 1fb09395fd31900c8ad7ff86fd0a10a4c24e1579 Mon Sep 17 00:00:00 2001 From: Moritz Jung Date: Sat, 22 Jun 2024 15:53:07 +0200 Subject: [PATCH] fix some small things --- src/api/APIManager.ts | 15 ++++++--------- src/api/APIModel.ts | 11 +++-------- src/main.ts | 1 + src/utils/ModalHelper.ts | 8 ++++---- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/api/APIManager.ts b/src/api/APIManager.ts index 3340a67..66246b9 100644 --- a/src/api/APIManager.ts +++ b/src/api/APIManager.ts @@ -17,20 +17,17 @@ export class APIManager { async query(query: string, apisToQuery: string[]): Promise { console.debug(`MDB | api manager queried with "${query}"`); - let res: MediaTypeModel[] = []; - - for (const api of this.apis) { - if (apisToQuery.contains(api.apiName)) { + const promises = this.apis + .filter(api => apisToQuery.contains(api.apiName)) + .map(async api => { try { - const apiRes = await api.searchByTitle(query); - res = res.concat(apiRes); + return await api.searchByTitle(query); } catch (e) { console.warn(e); } - } - } + }); - return res; + return (await Promise.all(promises)).flat(); } /** diff --git a/src/api/APIModel.ts b/src/api/APIModel.ts index 3d1204e..00ce961 100644 --- a/src/api/APIModel.ts +++ b/src/api/APIModel.ts @@ -18,22 +18,17 @@ export abstract class APIModel { abstract getById(id: string): Promise; - hasType(_type: MediaType): boolean { + hasType(type: MediaType): boolean { // if ( // this.types.contains(type) && // (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined) // ) { // return true; // } - return true; + return this.types.contains(type); } hasTypeOverlap(types: MediaType[]): boolean { - for (const type of types) { - if (this.hasType(type)) { - return true; - } - } - return false; + return types.some(type => this.hasType(type)); } } diff --git a/src/main.ts b/src/main.ts index 60faa26..678505a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin { types = searchModalData.types; const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName); try { + console.log(apis); return await this.apiManager.query(searchModalData.query, apis); } catch (e) { console.warn(e); diff --git a/src/utils/ModalHelper.ts b/src/utils/ModalHelper.ts index 6a4efa1..2a44913 100644 --- a/src/utils/ModalHelper.ts +++ b/src/utils/ModalHelper.ts @@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal'; import { MediaType } from './MediaType'; export enum ModalResultCode { - SUCCESS, - SKIP, - CLOSE, - ERROR, + SUCCESS = 'SUCCESS', + SKIP = 'SKIP', + CLOSE = 'CLOSE', + ERROR = 'ERROR', } /**