From 0ebefb5271b96fb5c103224c21655713d93a99f5 Mon Sep 17 00:00:00 2001 From: tylercchase Date: Wed, 17 Jul 2024 10:10:40 -0400 Subject: [PATCH] feat: better search effect --- src/app/services/search-params.service.ts | 4 +- src/app/store/search/search.effect.ts | 55 ++++++++++++++--------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/app/services/search-params.service.ts b/src/app/services/search-params.service.ts index 9b249ea89..234c664e6 100644 --- a/src/app/services/search-params.service.ts +++ b/src/app/services/search-params.service.ts @@ -226,7 +226,9 @@ export class SearchParamsService { private timeseriesParams$ = combineLatest([ this.searchPolygon$, - this.burstParams$ + this.burstParams$, + this.maxResults$, + this.selectedDataset$, ]).pipe( map((params: any[]) => params .reduce( diff --git a/src/app/store/search/search.effect.ts b/src/app/store/search/search.effect.ts index 93ad822f9..188b29074 100644 --- a/src/app/store/search/search.effect.ts +++ b/src/app/store/search/search.effect.ts @@ -54,6 +54,7 @@ export class SearchEffects { private sarviewsService: services.SarviewsEventsService, private http: HttpClient, private notificationService: services.NotificationService, + private netCdfService: services.NetcdfServiceService ) { } public clearMapInteractionModeOnSearch = createEffect(() => this.actions$.pipe( @@ -573,28 +574,38 @@ export class SearchEffects { } private timeseriesQuery$() { - return of(new TimeseriesSearchResponse({})) - // this.netCdfService.getTimeSeries({'lon': 1, 'lat':1}).pipe( - // map(_stuff => { - // console.log(_stuff) - // return of(new TimeseriesSearchResponse({})) - // }) - // ) - // return combineLatest( - // this.asfApiQuery$, - // this.searchParams$.getParams.pipe( - // map(params => { - // this.netCdfService.getTimeSeries(params) - // }) - // ) - // ).pipe( - // switchMap(([_project, _test]) => { - // console.log(_project) - // return of(new TimeseriesSearchResponse({})) - // }) - // results => { - // ) - // } + return this.searchParams$.getParams.pipe( + switchMap( + (params) => + this.asfApiService.query(params).pipe( + withLatestFrom(combineLatest([ + this.store$.select(getSearchType), + this.store$.select(getIsCanceled), + this.netCdfService.getTimeSeries({'lon': 1, 'lat':1}) // eventually grab params for points in this part + ] + )), + map(([response, [searchType, isCanceled, timseries]]) => { + const files = this.productService.fromResponse(response) + return !isCanceled ? + new TimeseriesSearchResponse({ + files, + totalCount: files.length, + searchType, + timseries + }) : + new SearchCanceled() + } + ), + catchError( + (err: HttpErrorResponse) => { + if (err.status !== 400) { + return of(new SearchError(`Unknown Error`)); + } + return EMPTY; + } + ), + )) + ); } private hyp3JobToProducts(jobs, products) {