[feature-136] can now search models from the download modal

This commit is contained in:
MathieuG-P
2023-05-16 00:50:47 +02:00
parent eb9775c89f
commit 645f18002a
22 changed files with 336 additions and 109 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import { Observable } from "rxjs";
import { IpcRequest, IpcResponse } from "shared/models/ipc";
import { identity } from "rxjs";
export class IpcService {
export class IpcService{
private static instance: IpcService;
@@ -4,7 +4,7 @@ import { BsmLocalModel } from "shared/models/models/bsm-local-model.interface";
import { MSModel, MSModelType } from "shared/models/models/model-saber.model";
import { ModalResponse, ModalService } from "../modale.service";
import { IpcService } from "../ipc.service";
import { DownloadMapsModal } from "renderer/components/modal/modal-types/download-maps-modal.component";
import { DownloadModelsModal } from "renderer/components/modal/modal-types/models/download-models-modal.component";
export class ModelsDownloaderService {
@@ -20,14 +20,14 @@ export class ModelsDownloaderService {
private readonly lastDownloadedModel$ = new BehaviorSubject<ModelDownload>(null);
private readonly queue$ = new BehaviorSubject<ModelDownload[]>([]);
private readonly currentDownload$ = this.queue$.pipe(map(queue => queue.at(0)), distinctUntilChanged(), shareReplay(1));
private readonly _currentDownload$ = this.queue$.pipe(map(queue => queue.at(0)), distinctUntilChanged(), shareReplay(1));
private constructor(){
this.ipc = IpcService.getInstance();
this.modal = ModalService.getInsance();
this.currentDownload$.pipe(filter(v => !!v)).subscribe(model => this.downloadModel(model));
this._currentDownload$.pipe(filter(v => !!v)).subscribe(model => this.downloadModel(model));
}
private downloadModel(model: ModelDownload){
@@ -56,18 +56,22 @@ export class ModelsDownloaderService {
}
public isDownloading$(model: ModelDownload): Observable<boolean>{
return this.currentDownload$.pipe(map(current => {
return this._currentDownload$.pipe(map(current => {
if(!current){ return false; }
return current.hash === model.hash && current.version === model.version
}), distinctUntilChanged());
}
public currentDownload$(): Observable<ModelDownload>{
return this._currentDownload$;
}
public isPending$(model: ModelDownload): Observable<boolean>{
return this.queue$.pipe(map(queue => queue.at(0).hash !== model.hash && queue.at(0).version !== model.version && queue.some(m => m.hash === model.hash && m.version === model.version)), distinctUntilChanged());
}
public openDownloadModelsModal(version: BSVersion, type?: MSModelType): Promise<ModalResponse<void>>{
return this.modal.openModal(DownloadMapsModal, {version: null, ownedMaps: []}); // TODO MODELS
return this.modal.openModal(DownloadModelsModal, {version, type}); // TODO MODELS
}
}
@@ -1,5 +1,6 @@
import { MSModel } from "shared/models/models/model-saber.model";
import { MSGetQuery, MSGetQueryFilter, MSGetQueryFilterType, MSModel } from "shared/models/models/model-saber.model";
import { IpcService } from "../ipc.service";
import { Observable } from "rxjs";
export class ModelSaberService {
@@ -22,4 +23,26 @@ export class ModelSaberService {
return res.data;
}
public searchModels(query: MSGetQuery): Observable<MSModel[]>{
return this.ipc.sendV2("search-models", {args: query});
}
public parseFilter(stringFilters: string): MSGetQueryFilter[]{
return stringFilters.split(" ").map(value => {
let trimed = value.trim();
const isNegative = trimed.at(0) === "-";
if(isNegative){
trimed = trimed.substring(0);
}
if(!trimed.includes(":")){
return {type: MSGetQueryFilterType.SearchName, value: trimed, isNegative}
}
});
}
}