Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: search query being discarded on first load #326

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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