From c81a8297b77c6d145aab80fb9fe7a269c2a4cb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Sun, 8 Jan 2023 17:33:22 +0100 Subject: [PATCH] Login page lifecycle fix --- .../login-page/login-page.component.ts | 30 ++++++++++++++----- .../notifications.component.scss | 8 ++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Frontend/src/app/components/login-page/login-page.component.ts b/Frontend/src/app/components/login-page/login-page.component.ts index b4bb825..2598f0a 100644 --- a/Frontend/src/app/components/login-page/login-page.component.ts +++ b/Frontend/src/app/components/login-page/login-page.component.ts @@ -59,7 +59,10 @@ export class LoginPageComponent implements OnInit { email: responsePayload.email, avatar: responsePayload.picture }); - this.loading = true; + this.ngZone$.run(() => { + this.loading = true; + }); + await this.sleep(2500); await this.auth$.getAPIToken(response.credential); this.ngZone$.run(() => { this.router$.navigate(['/app']); @@ -67,21 +70,32 @@ export class LoginPageComponent implements OnInit { // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { console.error('handleCredentialResponse', e); - this.loading = false; + this.ngZone$.run(() => { + this.loading = false; + }); if (e.status === 401) { - this.notifications$.add({ - text: "Użytkownik nie istnieje w bazie danych aplikacji DiunaBI.", - duration: 2500 + this.ngZone$.run(() => { + this.notifications$.add({ + text: "Użytkownik nie istnieje w bazie danych aplikacji DiunaBI.", + btn: "OK", + duration: 15000 + }); }); } else { - this.notifications$.add({ - text: "Błąd połączenia z serwerem. Skontaktuj się z administratorem.", - duration: 2500 + this.ngZone$.run(() => { + this.notifications$.add({ + text: "Błąd połączenia z serwerem. Skontaktuj się z administratorem.", + btn: "OK", + duration: 15000 + }); }); } } finally { this.loading = false; } } + sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); + } } diff --git a/Frontend/src/app/components/notifications/notifications.component.scss b/Frontend/src/app/components/notifications/notifications.component.scss index 98dcdbf..3b2e934 100644 --- a/Frontend/src/app/components/notifications/notifications.component.scss +++ b/Frontend/src/app/components/notifications/notifications.component.scss @@ -6,12 +6,10 @@ mat-card { cursor: pointer; } .text { - display: inline-block; - width: 70%; + float: left; } .btn { - display: inline-block; - width: 30%; - text-align: right; + float: right; color: red; + margin-left: 5px; } \ No newline at end of file