From 9ae18244d87b2ffb3a762b2547346f08442ccf71 Mon Sep 17 00:00:00 2001 From: till_schuetze Date: Fri, 1 Nov 2024 08:47:19 +0100 Subject: [PATCH 1/3] revert the changes that removed the RedirectToLangComponent and caused asset.viewer to display not found page --- apps/client-asset-sg/src/app/app.module.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/client-asset-sg/src/app/app.module.ts b/apps/client-asset-sg/src/app/app.module.ts index fa41b816..87ca5cd0 100644 --- a/apps/client-asset-sg/src/app/app.module.ts +++ b/apps/client-asset-sg/src/app/app.module.ts @@ -17,6 +17,7 @@ import { AdminOnlyDirective, AlertModule, AnchorComponent, + assetsPageMatcher, ButtonComponent, CanCreateDirective, CURRENT_LANG, @@ -24,7 +25,6 @@ import { icons, TranslateTsLoader, } from '@asset-sg/client-shared'; -import { assetsPageMatcher } from '@asset-sg/client-shared'; import { storeLogger } from '@asset-sg/core'; import { provideSvgIcons, SvgIconComponent } from '@ngneat/svg-icon'; import { EffectsModule } from '@ngrx/effects'; @@ -78,9 +78,13 @@ registerLocaleData(locale_deCH, 'de-CH'); loadChildren: () => import('@asset-sg/asset-viewer').then((m) => m.AssetViewerModule), }, { - path: '**', + path: 'not-found', component: NotFoundComponent, }, + { + path: '**', + component: RedirectToLangComponent, + }, ]), TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: () => new TranslateTsLoader(appTranslations) }, From 0a5b167b532430cc6a10c5d45fdd6ec780ea61f4 Mon Sep 17 00:00:00 2001 From: till_schuetze Date: Fri, 1 Nov 2024 10:42:39 +0100 Subject: [PATCH 2/3] use withLAtestFrom for queryParams --- .../src/lib/state/asset-search/asset-search.effects.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 b8ae789d..e671aa8d 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 @@ -16,11 +16,11 @@ import { AssetSearchService } from '../../services/asset-search.service'; import * as actions from './asset-search.actions'; import { + selectAssetSearchNoActiveFilters, selectAssetSearchQuery, + selectAssetSearchResultData, selectCurrentAssetDetail, - selectAssetSearchNoActiveFilters, selectStudies, - selectAssetSearchResultData, } from './asset-search.selector'; @UntilDestroy() @@ -205,9 +205,10 @@ export class AssetSearchEffects { concatLatestFrom(() => [ this.store.select(selectAssetSearchQuery), this.store.select(selectCurrentAssetDetail), - this.queryParams$, ]), - switchMap(([_, query, assetDetail, queryParams]) => { + withLatestFrom(this.queryParams$), + switchMap(([[_, query, assetDetail], queryParams]) => { + console.log('updateQueryParams', query, assetDetail, queryParams); const params: Params = { assetId: assetDetail?.assetId ?? queryParams.assetId }; updatePlainParam(params, QUERY_PARAM_MAPPING.text, query.text); updateArrayParam( From e39efd652289e3607018c556ea1779a19764382a Mon Sep 17 00:00:00 2001 From: till_schuetze Date: Fri, 1 Nov 2024 12:10:21 +0100 Subject: [PATCH 3/3] fix open in new link and reload --- .../redirect-to-lang.component.ts | 30 ++++--------------- .../asset-search/asset-search.effects.ts | 11 ++++--- libs/auth/src/lib/services/auth.service.ts | 12 ++++++-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/apps/client-asset-sg/src/app/components/redirect-to-lang/redirect-to-lang.component.ts b/apps/client-asset-sg/src/app/components/redirect-to-lang/redirect-to-lang.component.ts index afb8402f..42561142 100644 --- a/apps/client-asset-sg/src/app/components/redirect-to-lang/redirect-to-lang.component.ts +++ b/apps/client-asset-sg/src/app/components/redirect-to-lang/redirect-to-lang.component.ts @@ -1,11 +1,7 @@ import { Component } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; import { AuthService } from '@asset-sg/auth'; -import { Lang } from '@asset-sg/shared'; -import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import * as E from 'fp-ts/Either'; -import * as D from 'io-ts/Decoder'; -import queryString from 'query-string'; +import { UntilDestroy } from '@ngneat/until-destroy'; @UntilDestroy() @Component({ @@ -13,24 +9,10 @@ import queryString from 'query-string'; template: 'Redirect to main page...', }) export class RedirectToLangComponent { - constructor(route: ActivatedRoute, router: Router, authService: AuthService) { - route.queryParams.pipe(untilDestroyed(this)).subscribe((params) => { - const paramsDecoded = D.struct({ - lang: Lang, - }).decode(params); - - if (E.isRight(paramsDecoded)) { - const { url, query } = queryString.parseUrl(router.url); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { lang, ...rest } = query; - const newUrl = `/${paramsDecoded.right.lang}${url}?${queryString.stringify(rest)}`; - router.navigateByUrl(newUrl); - } else if (!authService.isLoggedIn()) { - setTimeout(() => { - router.navigate(['/de']); - }, 500); - } else { - router.navigate(['/de']); + constructor(router: Router, authService: AuthService) { + authService.isInitialized$.subscribe((isInitialized) => { + if (isInitialized) { + router.navigate(['/de'], { queryParamsHandling: 'merge' }); } }); } 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 e671aa8d..f0c7aa5f 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 @@ -9,7 +9,7 @@ import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; import { ROUTER_NAVIGATED } from '@ngrx/router-store'; import { Store } from '@ngrx/store'; import * as D from 'io-ts/Decoder'; -import { EMPTY, filter, map, merge, of, share, switchMap, takeUntil, withLatestFrom } from 'rxjs'; +import { EMPTY, filter, map, merge, of, shareReplay, switchMap, takeUntil, withLatestFrom } from 'rxjs'; import { AllStudyService } from '../../services/all-study.service'; import { AssetSearchService } from '../../services/asset-search.service'; @@ -162,7 +162,7 @@ export class AssetSearchEffects { query.workgroupIds = readArrayParam(params, QUERY_PARAM_MAPPING.workgroupIds); return { query, assetId }; }), - share() + shareReplay() ); public readSearchQueryParams$ = createEffect(() => @@ -201,14 +201,13 @@ export class AssetSearchEffects { public updateQueryParams$ = createEffect( () => this.actions$.pipe( - ofType(actions.updateQueryParams, actions.updateAssetDetail, actions.resetAssetDetail), + ofType(actions.updateQueryParams, actions.updateAssetDetail, actions.resetAssetDetail, actions.loadSearch), concatLatestFrom(() => [ this.store.select(selectAssetSearchQuery), this.store.select(selectCurrentAssetDetail), + this.queryParams$, ]), - withLatestFrom(this.queryParams$), - switchMap(([[_, query, assetDetail], queryParams]) => { - console.log('updateQueryParams', query, assetDetail, queryParams); + switchMap(([_, query, assetDetail, queryParams]) => { const params: Params = { assetId: assetDetail?.assetId ?? queryParams.assetId }; updatePlainParam(params, QUERY_PARAM_MAPPING.text, query.text); updateArrayParam( diff --git a/libs/auth/src/lib/services/auth.service.ts b/libs/auth/src/lib/services/auth.service.ts index 44386f94..73344da8 100644 --- a/libs/auth/src/lib/services/auth.service.ts +++ b/libs/auth/src/lib/services/auth.service.ts @@ -18,6 +18,7 @@ export class AuthService { private readonly router = inject(Router); private readonly _state$ = new BehaviorSubject(AuthState.Ongoing); + private readonly _isInitialized$ = new BehaviorSubject(false); async initialize(oAuthConfig: Record) { if (oAuthConfig['anonymous_mode']) { @@ -25,7 +26,7 @@ export class AuthService { this.store.dispatch(appSharedStateActions.setAnonymousMode()); } else { const callbackUrl = sessionStorage.getItem(CALLBACK_PATH_KEY); - sessionStorage.setItem(CALLBACK_PATH_KEY, this.router.url); + sessionStorage.setItem(CALLBACK_PATH_KEY, window.location.pathname + window.location.search); this.configureOAuth( oAuthConfig['oauth_issuer'] as string, oAuthConfig['oauth_clientId'] as string, @@ -35,11 +36,14 @@ export class AuthService { ); await this.signIn(); if (callbackUrl != null) { - sessionStorage.removeItem(CALLBACK_PATH_KEY); await this.router.navigateByUrl(callbackUrl); } + if (this.oauthService.hasValidAccessToken()) { + sessionStorage.removeItem(CALLBACK_PATH_KEY); + } this.store.dispatch(appSharedStateActions.loadUserProfile()); } + this._isInitialized$.next(true); } async signIn(): Promise { @@ -71,6 +75,10 @@ export class AuthService { return this._state$.asObservable(); } + get isInitialized$(): Observable { + return this._isInitialized$.asObservable(); + } + setState(state: AuthState): void { this._state$.next(state); }