From 233064a822daf372e35c9904e62ac6bc9dec2ef8 Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Wed, 30 Oct 2024 11:33:10 +0100 Subject: [PATCH] Fix search query being discarded on first load --- apps/client-asset-sg/src/app/app.module.ts | 6 +----- .../src/lib/state/asset-search/asset-search.effects.ts | 5 ++--- libs/auth/src/lib/services/auth.service.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/client-asset-sg/src/app/app.module.ts b/apps/client-asset-sg/src/app/app.module.ts index 6f6aa4e8..fa41b816 100644 --- a/apps/client-asset-sg/src/app/app.module.ts +++ b/apps/client-asset-sg/src/app/app.module.ts @@ -77,13 +77,9 @@ registerLocaleData(locale_deCH, 'de-CH'); matcher: assetsPageMatcher, loadChildren: () => import('@asset-sg/asset-viewer').then((m) => m.AssetViewerModule), }, - { - path: 'not-found', - component: NotFoundComponent, - }, { path: '**', - component: RedirectToLangComponent, + component: NotFoundComponent, }, ]), TranslateModule.forRoot({ diff --git a/libs/asset-viewer/src/lib/state/asset-search/asset-search.effects.ts b/libs/asset-viewer/src/lib/state/asset-search/asset-search.effects.ts index 62f3dad6..d49513a9 100644 --- a/libs/asset-viewer/src/lib/state/asset-search/asset-search.effects.ts +++ b/libs/asset-viewer/src/lib/state/asset-search/asset-search.effects.ts @@ -192,8 +192,7 @@ export class AssetSearchEffects { withLatestFrom(this.store.select(selectCurrentAssetDetail)), filter(([params, storeAssetDetail]) => params.assetId !== storeAssetDetail?.assetId), map(([params, storeAssetDetail]) => { - const paramsEmpty = Object.values(params.query).every((v) => v == null); - const assetId = paramsEmpty ? storeAssetDetail?.assetId : params.assetId; + const assetId = storeAssetDetail?.assetId ?? params.assetId; return assetId === undefined ? actions.resetAssetDetail() : actions.showAssetDetail({ assetId }); }) ) @@ -202,7 +201,7 @@ export class AssetSearchEffects { public updateQueryParams$ = createEffect( () => this.actions$.pipe( - ofType(actions.updateQueryParams, actions.loadSearch, actions.updateAssetDetail, actions.resetAssetDetail), + ofType(actions.updateQueryParams, actions.updateAssetDetail, actions.resetAssetDetail), concatLatestFrom(() => [ this.store.select(selectAssetSearchQuery), this.store.select(selectCurrentAssetDetail), diff --git a/libs/auth/src/lib/services/auth.service.ts b/libs/auth/src/lib/services/auth.service.ts index c5b1bb6a..44386f94 100644 --- a/libs/auth/src/lib/services/auth.service.ts +++ b/libs/auth/src/lib/services/auth.service.ts @@ -1,5 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; +import { Router } from '@angular/router'; import { ApiError, appSharedStateActions, AppState } from '@asset-sg/client-shared'; import { ORD } from '@asset-sg/core'; import { User, UserSchema } from '@asset-sg/shared/v2'; @@ -14,6 +15,7 @@ export class AuthService { private readonly httpClient = inject(HttpClient); private readonly oauthService = inject(OAuthService); private readonly store = inject(Store); + private readonly router = inject(Router); private readonly _state$ = new BehaviorSubject(AuthState.Ongoing); @@ -22,6 +24,8 @@ export class AuthService { this.setState(AuthState.Success); this.store.dispatch(appSharedStateActions.setAnonymousMode()); } else { + const callbackUrl = sessionStorage.getItem(CALLBACK_PATH_KEY); + sessionStorage.setItem(CALLBACK_PATH_KEY, this.router.url); this.configureOAuth( oAuthConfig['oauth_issuer'] as string, oAuthConfig['oauth_clientId'] as string, @@ -30,6 +34,10 @@ export class AuthService { oAuthConfig['oauth_tokenEndpoint'] as string ); await this.signIn(); + if (callbackUrl != null) { + sessionStorage.removeItem(CALLBACK_PATH_KEY); + await this.router.navigateByUrl(callbackUrl); + } this.store.dispatch(appSharedStateActions.loadUserProfile()); } } @@ -111,6 +119,8 @@ export class AuthService { } } +const CALLBACK_PATH_KEY = 'session.callback_path'; + export enum AuthState { Ongoing, Aborted,