From 3a2b92b3ffc7dabeb57b27a06d9f642e2340c5c0 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 12 Feb 2025 12:19:31 +0100 Subject: [PATCH 1/3] feat: Convert login button to hompage button when user is authenticated --- .../src/app/landing-page/landing-page.component.html | 6 +++++- .../src/app/landing-page/landing-page.component.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/landing-page/landing-page.component.html b/frontend/src/app/landing-page/landing-page.component.html index aa8bbd8..944881c 100644 --- a/frontend/src/app/landing-page/landing-page.component.html +++ b/frontend/src/app/landing-page/landing-page.component.html @@ -1 +1,5 @@ - +@if (isLoggedIn) { + +} @else { + +} diff --git a/frontend/src/app/landing-page/landing-page.component.ts b/frontend/src/app/landing-page/landing-page.component.ts index f7509cf..f5fee0c 100644 --- a/frontend/src/app/landing-page/landing-page.component.ts +++ b/frontend/src/app/landing-page/landing-page.component.ts @@ -1,16 +1,24 @@ import { Component, inject } from '@angular/core'; import { KeycloakService } from 'keycloak-angular'; +import {RouterLink} from "@angular/router"; @Component({ selector: 'app-landing-page', standalone: true, - imports: [], + imports: [ + RouterLink + ], templateUrl: './landing-page.component.html', }) export class LandingPageComponent { + public isLoggedIn = false; private keycloakService: KeycloakService = inject(KeycloakService); - login() { + private ngOnInit() { + this.isLoggedIn = this.keycloakService.isLoggedIn(); + } + + public login() { const baseUrl = window.location.origin; this.keycloakService.login({ redirectUri: `${baseUrl}/home` }); From 22086a88fae7a5806eb31106b30a4a4e1606c192 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 12 Feb 2025 12:20:57 +0100 Subject: [PATCH 2/3] style: Run prettier --- frontend/src/app/landing-page/landing-page.component.html | 4 ++-- frontend/src/app/landing-page/landing-page.component.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/landing-page/landing-page.component.html b/frontend/src/app/landing-page/landing-page.component.html index 944881c..80d5974 100644 --- a/frontend/src/app/landing-page/landing-page.component.html +++ b/frontend/src/app/landing-page/landing-page.component.html @@ -1,5 +1,5 @@ @if (isLoggedIn) { - + } @else { - + } diff --git a/frontend/src/app/landing-page/landing-page.component.ts b/frontend/src/app/landing-page/landing-page.component.ts index f5fee0c..3b6292b 100644 --- a/frontend/src/app/landing-page/landing-page.component.ts +++ b/frontend/src/app/landing-page/landing-page.component.ts @@ -1,13 +1,11 @@ import { Component, inject } from '@angular/core'; import { KeycloakService } from 'keycloak-angular'; -import {RouterLink} from "@angular/router"; +import { RouterLink } from '@angular/router'; @Component({ selector: 'app-landing-page', standalone: true, - imports: [ - RouterLink - ], + imports: [RouterLink], templateUrl: './landing-page.component.html', }) export class LandingPageComponent { From ab3bc5587eeed0197d4df7bb83410e196879be9f Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 12 Feb 2025 12:33:52 +0100 Subject: [PATCH 3/3] refactor: remove oninit --- frontend/src/app/landing-page/landing-page.component.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/src/app/landing-page/landing-page.component.ts b/frontend/src/app/landing-page/landing-page.component.ts index 3b6292b..1291434 100644 --- a/frontend/src/app/landing-page/landing-page.component.ts +++ b/frontend/src/app/landing-page/landing-page.component.ts @@ -9,12 +9,9 @@ import { RouterLink } from '@angular/router'; templateUrl: './landing-page.component.html', }) export class LandingPageComponent { - public isLoggedIn = false; private keycloakService: KeycloakService = inject(KeycloakService); - private ngOnInit() { - this.isLoggedIn = this.keycloakService.isLoggedIn(); - } + public isLoggedIn = this.keycloakService.isLoggedIn(); public login() { const baseUrl = window.location.origin;