Skip to content

Commit 1fb0939

Browse files
committed
fix some small things
1 parent 4dcffab commit 1fb0939

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/api/APIManager.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@ export class APIManager {
1717
async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> {
1818
console.debug(`MDB | api manager queried with "${query}"`);
1919

20-
let res: MediaTypeModel[] = [];
21-
22-
for (const api of this.apis) {
23-
if (apisToQuery.contains(api.apiName)) {
20+
const promises = this.apis
21+
.filter(api => apisToQuery.contains(api.apiName))
22+
.map(async api => {
2423
try {
25-
const apiRes = await api.searchByTitle(query);
26-
res = res.concat(apiRes);
24+
return await api.searchByTitle(query);
2725
} catch (e) {
2826
console.warn(e);
2927
}
30-
}
31-
}
28+
});
3229

33-
return res;
30+
return (await Promise.all(promises)).flat();
3431
}
3532

3633
/**

src/api/APIModel.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@ export abstract class APIModel {
1818

1919
abstract getById(id: string): Promise<MediaTypeModel>;
2020

21-
hasType(_type: MediaType): boolean {
21+
hasType(type: MediaType): boolean {
2222
// if (
2323
// this.types.contains(type) &&
2424
// (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type]) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] === undefined)
2525
// ) {
2626
// return true;
2727
// }
28-
return true;
28+
return this.types.contains(type);
2929
}
3030

3131
hasTypeOverlap(types: MediaType[]): boolean {
32-
for (const type of types) {
33-
if (this.hasType(type)) {
34-
return true;
35-
}
36-
}
37-
return false;
32+
return types.some(type => this.hasType(type));
3833
}
3934
}

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export default class MediaDbPlugin extends Plugin {
195195
types = searchModalData.types;
196196
const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName);
197197
try {
198+
console.log(apis);
198199
return await this.apiManager.query(searchModalData.query, apis);
199200
} catch (e) {
200201
console.warn(e);

src/utils/ModalHelper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
99
import { MediaType } from './MediaType';
1010

1111
export enum ModalResultCode {
12-
SUCCESS,
13-
SKIP,
14-
CLOSE,
15-
ERROR,
12+
SUCCESS = 'SUCCESS',
13+
SKIP = 'SKIP',
14+
CLOSE = 'CLOSE',
15+
ERROR = 'ERROR',
1616
}
1717

1818
/**

0 commit comments

Comments
 (0)