From 0ec30a4a44d6f327cbbd6918026ae82e45cc1067 Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Thu, 27 Aug 2020 17:04:22 +0200 Subject: [PATCH] [frontend] Finish navigation bar --- .../app/shared/toolbar/toolbar.component.html | 39 +++++++++---------- .../app/shared/toolbar/toolbar.component.scss | 2 +- .../app/shared/toolbar/toolbar.component.ts | 30 ++++++++++++-- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.html b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.html index a632fa2..f7437d3 100644 --- a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.html +++ b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.html @@ -1,25 +1,22 @@ - - Kibicara - - +
+ Dashboard + Logout +
+ + Login +
diff --git a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.scss b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.scss index 9633d15..02193a7 100644 --- a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.scss +++ b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.scss @@ -1,3 +1,3 @@ .example-spacer { - flex: 1 1 auto; + flex: 1 auto; } diff --git a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.ts b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.ts index 16fb31d..8fa79f1 100644 --- a/kibicara-frontend/src/app/shared/toolbar/toolbar.component.ts +++ b/kibicara-frontend/src/app/shared/toolbar/toolbar.component.ts @@ -1,15 +1,39 @@ import { Component, OnInit } from '@angular/core'; +import { LoginService } from 'src/app/core/auth/login.service'; +import { Observer } from 'rxjs'; +import { Route } from '@angular/compiler/src/core'; +import { Router, NavigationEnd } from '@angular/router'; +import { first, map } from 'rxjs/operators'; @Component({ selector: 'app-toolbar', templateUrl: './toolbar.component.html', - styleUrls: ['./toolbar.component.scss'] + styleUrls: ['./toolbar.component.scss'], }) export class ToolbarComponent implements OnInit { + authenticated = false; - constructor() { } + constructor(private loginService: LoginService, private router: Router) { + this.router.routeReuseStrategy.shouldReuseRoute = function () { + return false; + }; - ngOnInit(): void { + this.router.events.subscribe((event) => { + if (event instanceof NavigationEnd) { + this.router.navigated = false; + if (this.loginService.currentHoodAdminValue) { + this.authenticated = true; + } else { + this.authenticated = false; + } + } + }); } + ngOnInit(): void {} + + onLogout() { + this.loginService.logout(); + this.router.navigate(['/']); + } }