Skip to content

Commit

Permalink
Fix search query being discarded on first load
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-va committed Oct 30, 2024
1 parent 7838952 commit 233064a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 1 addition & 5 deletions apps/client-asset-sg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
})
)
Expand All @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions libs/auth/src/lib/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,6 +15,7 @@ export class AuthService {
private readonly httpClient = inject(HttpClient);
private readonly oauthService = inject(OAuthService);
private readonly store = inject(Store<AppState>);
private readonly router = inject(Router);

private readonly _state$ = new BehaviorSubject(AuthState.Ongoing);

Expand All @@ -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,
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -111,6 +119,8 @@ export class AuthService {
}
}

const CALLBACK_PATH_KEY = 'session.callback_path';

export enum AuthState {
Ongoing,
Aborted,
Expand Down

0 comments on commit 233064a

Please sign in to comment.