1
- import { Component } from '@angular/core' ;
1
+ import { CommonModule } from '@angular/common' ;
2
+ import { Component , HostListener } from '@angular/core' ;
2
3
import { RouterModule } from '@angular/router' ;
3
4
import { FaIconComponent } from '@fortawesome/angular-fontawesome' ;
4
- import { faCoffee , faHouse , faMagnifyingGlass , faQuestion , faUser , faEye } from '@fortawesome/free-solid-svg-icons' ;
5
+ import { faCoffee , faEye , faHouse , faMagnifyingGlass , faQuestion , faUser } from '@fortawesome/free-solid-svg-icons' ;
6
+
7
+ import { IUser } from '../../shared/models/iuser' ;
8
+ import { AuthService } from '../../shared/services/auth-service.service' ;
9
+ import { DonationService } from '../../shared/services/donations.service' ;
10
+ import { UserService } from '../../shared/services/user.service' ;
5
11
6
12
@Component ( {
7
13
selector : 'app-navbar-mobile' ,
8
14
standalone : true ,
9
- imports : [ RouterModule , FaIconComponent ] ,
15
+ imports : [ RouterModule , FaIconComponent , CommonModule ] ,
10
16
templateUrl : './navbar-mobile.component.html' ,
11
17
styleUrl : './navbar-mobile.component.scss' ,
12
18
} )
@@ -17,4 +23,39 @@ export class NavbarMobileComponent {
17
23
faQuestion = faQuestion ;
18
24
faUser = faUser ;
19
25
faEye = faEye ;
26
+ userInfo : IUser | null = null ;
27
+ isDropdownVisible = false ;
28
+ donationQueueLength = 0 ;
29
+
30
+ constructor (
31
+ private userService : UserService ,
32
+ private authService : AuthService ,
33
+ private donationService : DonationService
34
+ ) {
35
+ this . donationService . getDonationQueueLength ( ) . subscribe ( length => {
36
+ this . donationQueueLength = length ;
37
+ } ) ;
38
+ this . userService . userInfo$ . subscribe ( user => {
39
+ this . userInfo = user ;
40
+ } ) ;
41
+ }
42
+
43
+ isAuthenticated ( ) : boolean {
44
+ return this . userService . isAuthenticated ( ) ;
45
+ }
46
+
47
+ logout ( ) : void {
48
+ this . authService . logout ( ) . subscribe ( ) ;
49
+ }
50
+
51
+ toggleDropdown ( ) {
52
+ this . isDropdownVisible = ! this . isDropdownVisible ;
53
+ }
54
+ @HostListener ( 'document:click' , [ '$event' ] )
55
+ handleClickOutside ( event : Event ) {
56
+ const target = event . target as HTMLElement ;
57
+ if ( ! target . closest ( '.profile-menu' ) ) {
58
+ this . isDropdownVisible = false ;
59
+ }
60
+ }
20
61
}
0 commit comments