1 | import {Component, OnInit} from '@angular/core';
|
---|
2 | import {AuthService} from "../../services/auth/auth.service";
|
---|
3 | import {Router, RouterLink} from "@angular/router";
|
---|
4 | import {switchMap} from "rxjs";
|
---|
5 | import {UserResponse} from "../../model/responses/UserResponse";
|
---|
6 | import {UserService} from "../../services/user/user.service";
|
---|
7 | import {MatMenuModule} from '@angular/material/menu';
|
---|
8 | import {MatButtonModule} from '@angular/material/button';
|
---|
9 |
|
---|
10 | @Component({
|
---|
11 | selector: 'app-navigation',
|
---|
12 | standalone: true,
|
---|
13 | imports: [
|
---|
14 | RouterLink, MatButtonModule, MatMenuModule
|
---|
15 | ],
|
---|
16 | templateUrl: './navigation.component.html',
|
---|
17 | })
|
---|
18 | export class NavigationComponent implements OnInit {
|
---|
19 |
|
---|
20 | constructor(
|
---|
21 | private _authService: AuthService,
|
---|
22 | private _router: Router,
|
---|
23 | private _userService: UserService,
|
---|
24 | ) {
|
---|
25 | }
|
---|
26 |
|
---|
27 | user: UserResponse | undefined
|
---|
28 |
|
---|
29 | ngOnInit(): void {
|
---|
30 | this._authService.refreshAuth$.pipe(
|
---|
31 | switchMap(auth => this._userService.getUser())
|
---|
32 | ).subscribe({
|
---|
33 | next: user => {
|
---|
34 | console.log(user)
|
---|
35 | this.user = user
|
---|
36 | },
|
---|
37 | error: err => {
|
---|
38 | this.user = undefined
|
---|
39 | }
|
---|
40 | })
|
---|
41 |
|
---|
42 | this._userService.getUser().subscribe({
|
---|
43 | next: user => {
|
---|
44 | this.user = user
|
---|
45 | }
|
---|
46 | })
|
---|
47 | }
|
---|
48 |
|
---|
49 | isMenuOpen = false;
|
---|
50 | isIconMenuOpen = false;
|
---|
51 |
|
---|
52 | changeMenuState() {
|
---|
53 | console.log('changeMenuState');
|
---|
54 | this.isMenuOpen = !this.isMenuOpen;
|
---|
55 | }
|
---|
56 |
|
---|
57 | changeIconMenuState() {
|
---|
58 | console.log('changeIconMenuState');
|
---|
59 | this.isIconMenuOpen = !this.isIconMenuOpen;
|
---|
60 | }
|
---|
61 |
|
---|
62 | signOut() {
|
---|
63 | sessionStorage.clear()
|
---|
64 | this._authService.refreshAuth$.next(false)
|
---|
65 | }
|
---|
66 | }
|
---|