Skip to content

Commit

Permalink
feat: fakeLogin, clean take(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Oct 15, 2024
1 parent 78b4d77 commit 51cb774
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ export const updateLoggedInUser = (patcher: Patcher<UserInfo>) => {
currentlyLoggedInUser = patchObj<UserInfo>(currentlyLoggedInUser, patcher);
};

export const fakeLogin = () => {
currentlyLoggedInUser = buildUserInfo(
ALL_USERS['00000000-0000-0000-0000-000000000001'],
);
};

/**
* Fake implementation for "userInfo" endpoint
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
switchMap((isMyDataOffers) => {
if (isMyDataOffers) {
return this.globalStateUtils.userInfo$.pipe(
take(1),
map((it) => it.organizationId),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class ControlCenterUserEditPageStateImpl {
@Action(Reset)
onReset(ctx: Ctx, action: Reset): Observable<never> {
return this.globalStateUtils.userInfo$.pipe(
take(1),
switchMap((userInfo) =>
this.apiService.getUserDetailDto(userInfo.userId),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a
id="btn-login"
class="w-[300px] bg-black hover:bg-black text-white font-bold py-2 px-4 rounded active:scale-[0.99]"
[attr.href]="loginUrl">
(click)="login()">
Log In
</a>
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
import {Component, Inject} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {fakeLogin} from 'src/app/core/api/fake-backend/impl/fake-users';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';

@Component({
Expand All @@ -31,4 +32,12 @@ export class UnauthenticatedPageComponent {
url.searchParams.set('redirect_uri', location.href);
return url.toString();
}

login() {
if (this.appConfig.useFakeBackend) {
fakeLogin();
} else {
location.href = this.loginUrl;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class OrganizationOnboardPageStateImpl {
@Action(Reset, {cancelUncompleted: true})
onReset(ctx: StateContext<OrganizationOnboardPageState>): Observable<never> {
return this.globalStateUtils.userInfo$.pipe(
take(1),
switchMap((userInfo) =>
combineLatest([
this.apiService.getOrganizationUser(userInfo.userId),
Expand Down

0 comments on commit 51cb774

Please sign in to comment.