-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav.component.ts
77 lines (70 loc) · 2.17 KB
/
nav.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { PostsService } from './../../../post/services/posts.service';
import { Component, OnInit } from '@angular/core';
import { NavigationEnd, Router, Event } from '@angular/router';
import { filter } from 'rxjs';
import { AuthService } from 'src/app/auth/services/auth.service';
@Component({
selector: 'app-nav',
templateUrl: './nav.component.html',
styleUrls: ['./nav.component.css'],
})
export class NavComponent implements OnInit {
compassIconGlow: boolean = false;
heartIconGlow: boolean = false;
profileIconGlow: boolean = false;
filtered: boolean = false;
constructor(
private router: Router,
private authService: AuthService,
private postService: PostsService
) { }
ngOnInit(): void {
this.router.events
.pipe(
filter(
(event: Event): event is NavigationEnd =>
event instanceof NavigationEnd
)
)
.subscribe((event: NavigationEnd) => {
this.disableAllIcons();
const currentRoute: string = event.url;
if (currentRoute === '/') {
this.postService.getFilter().subscribe((filter: boolean) => {
if (filter) this.heartIconGlow = true;
else this._checkRoute(event, currentRoute);
});
} else this._checkRoute(event, currentRoute);
});
}
private _checkRoute(event: NavigationEnd, currentRoute: string) {
const redirectRoute: string = event.urlAfterRedirects;
if (redirectRoute === '/error') return;
if (currentRoute === '/') this.compassIconGlow = true
else if (
currentRoute.startsWith('/user') &&
this.authService.isLoggedIn()
) {
this.profileIconGlow = true;
}
}
toggleCompassIcon() {
this.disableAllIcons();
this.compassIconGlow = true;
this.filtered = false;
this.postService.setFilter(this.filtered);
}
toggleHeartIcon() {
if (!this.authService.isLoggedIn()) return;
this.disableAllIcons();
this.filtered = true;
this.postService.setFilter(this.filtered);
this.heartIconGlow = true;
}
disableAllIcons() {
this.compassIconGlow = false;
this.heartIconGlow = false;
this.filtered = false;
this.profileIconGlow = false;
}
}