aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/navbar/navbar.component.ts
diff options
context:
space:
mode:
authorKamen Mladenov <kamen.d.mladenov@protonmail.com>2021-03-22 20:52:19 +0200
committerGitHub <noreply@github.com>2021-03-22 20:52:19 +0200
commit0cbe73007b9112bf7aa76e2584cb1fafc272dd5b (patch)
tree69b9916c17b6675a1e33b1a180d5eb0615e4fb87 /src/app/components/navbar/navbar.component.ts
parent084238dfa39f31b3661362cbe8cdea44e8f05992 (diff)
parentcad20fc8c7d58860d7bf9c803da3a8fcea43396a (diff)
downloadDevHive-Angular-0cbe73007b9112bf7aa76e2584cb1fafc272dd5b.tar
DevHive-Angular-0cbe73007b9112bf7aa76e2584cb1fafc272dd5b.tar.gz
DevHive-Angular-0cbe73007b9112bf7aa76e2584cb1fafc272dd5b.zip
Merge pull request #3 from Team-Kaleidoscope/major-redesign
Major redesign
Diffstat (limited to 'src/app/components/navbar/navbar.component.ts')
-rw-r--r--src/app/components/navbar/navbar.component.ts62
1 files changed, 62 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..85f07d1
--- /dev/null
+++ b/src/app/components/navbar/navbar.component.ts
@@ -0,0 +1,62 @@
+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;
+ public loggedIn: Boolean;
+
+ constructor(private _router: Router, private _userService: UserService, private _tokenService: TokenService)
+ { }
+
+ ngOnInit(): void {
+ this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== '';
+
+ this.user = this._userService.getDefaultUser();
+ this.user.userName = ''; // so you don't always see a flash of 'Gosho'
+
+ this._userService.getUserFromSessionStorageRequest().subscribe({
+ next: (res: object) => {
+ Object.assign(this.user, res);
+ },
+ });
+ }
+
+ goToProfile(): void {
+ // Properly reload the page
+ // Needed because if you're on someone's profile and go to yours, angular won't refresh the page (with your info)
+ this._router.routeReuseStrategy.shouldReuseRoute = () => false;
+ this._router.onSameUrlNavigation = 'reload';
+
+ this._router.navigate(['/profile/' + this.user.userName]);
+ }
+
+ goToFeed(): void {
+ if (this.loggedIn) {
+ this._router.navigate(['/']);
+ }
+ else {
+ this.goToLogin();
+ }
+ }
+
+ goToSettings(): void {
+ this._router.navigate(['/profile/' + this.user.userName + '/settings']);
+ }
+
+ logout(): void {
+ this._tokenService.logoutUserFromSessionStorage();
+ this.goToLogin();
+ }
+
+ goToLogin(): void {
+ this._router.navigate(['/login']);
+ }
+}