diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-19 16:02:43 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-19 16:02:43 +0200 |
| commit | a9358fb8a27cd3d48547f5427797702ee2780de8 (patch) | |
| tree | 7925fe254d47f25b9a1322270cb18664f5c7f397 /src/app/components/navbar/navbar.component.ts | |
| parent | 5880656282edfb7dc1bb7073c20ccf74aad6a093 (diff) | |
| download | DevHive-Angular-a9358fb8a27cd3d48547f5427797702ee2780de8.tar DevHive-Angular-a9358fb8a27cd3d48547f5427797702ee2780de8.tar.gz DevHive-Angular-a9358fb8a27cd3d48547f5427797702ee2780de8.zip | |
Implemented navbar component; added some global stylings and changed the name of others; added icons
Diffstat (limited to 'src/app/components/navbar/navbar.component.ts')
| -rw-r--r-- | src/app/components/navbar/navbar.component.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/app/components/navbar/navbar.component.ts b/src/app/components/navbar/navbar.component.ts new file mode 100644 index 0000000..4af7a8a --- /dev/null +++ b/src/app/components/navbar/navbar.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { TokenService } from 'src/app/services/token.service'; +import { UserService } from 'src/app/services/user.service'; +import { User } from 'src/models/identity/user.model'; + +@Component({ + selector: 'app-navbar', + templateUrl: './navbar.component.html', + styleUrls: ['./navbar.component.css'] +}) +export class NavbarComponent implements OnInit { + public user: User; + + constructor(private _router: Router, private _userService: UserService, private _tokenService: TokenService) + { } + + ngOnInit(): void { + if (!this._tokenService.getTokenFromSessionStorage()) { + this._router.navigate(['/login']); + return; + } + + this.user = this._userService.getDefaultUser(); + + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (res: object) => { + Object.assign(this.user, res); + }, + }); + } + + goToProfile(): void { + this._router.navigate(['/profile/' + this.user.userName]); + } + + goToFeed(): void { + this._router.navigate(['/']); + } + + goToSettings(): void { + this._router.navigate(['/profile/' + this.user.userName + '/settings']); + } + + logout(): void { + this._tokenService.logoutUserFromSessionStorage(); + this._router.navigate(['/login']); + } +} |
