Website Summary Files Commits Branches @commit @diff @stats
path: root / src / app / components / navbar / navbar.component.ts
diff options
context:
space:
mode:
Commitf849e37ccdd6fd48f83119a3b3b65cdd8b765dc3 (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-04-09 19:55:59 +0300
Committer
 GitHub <noreply@github.com>
2021-04-09 19:55:59 +0300
Files83b88a773bb7dc053bb3aced35bce302264ec925 /src/app/components/navbar/navbar.component.ts
DevHive-Angular-main.tar
DevHive-Angular-main.tar.gz
DevHive-Angular-main.zip
Parentbcd88af53b1a920d728ec98b45daa9ac2e2c0917 (diff)
Parentc13889759d70687de6833c505221c203f65fedb8 (diff)
Merge pull request #7 from Team-Kaleidoscope/dev HEAD v0.2 main
Second Stage: Complete
1 files changed, 63 insertions, 0 deletions
-rw-r--r--src/app/components/navbar/navbar.component.ts63
diff --git a/src/app/components/navbar/navbar.component.ts b/src/app/components/navbar/navbar.component.ts
new file mode 100644
index 0000000..14b8f52
--- /dev/null
+++ b/src/app/components/navbar/navbar.component.ts
@@ -0,0 +1,63 @@
+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();
+
+ if (this.loggedIn) {
+ 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']);
+ }
+}