1- import { Component , ElementRef , ViewChild } from '@angular/core' ;
1+ import { Component , ElementRef , OnInit , ViewChild } from '@angular/core' ;
2+ import { ActivatedRoute , Router } from '@angular/router' ;
23
34import { AuthService } from '@services/auth.service' ;
45
@@ -7,15 +8,22 @@ import { AuthService } from '@services/auth.service';
78 templateUrl : './header.component.html' ,
89 styleUrls : [ './header.component.scss' ]
910} )
10- export class HeaderComponent {
11+ export class HeaderComponent implements OnInit {
1112 @ViewChild ( 'dropdownUser' ) dropdownUser : ElementRef ;
1213 @ViewChild ( 'inputSearch' ) inputSearch : ElementRef ;
1314 userActive = this . authService . userActive ;
15+ currentValueSearch = '' ;
1416
1517 constructor (
16- private authService : AuthService
18+ private authService : AuthService ,
19+ private router : Router ,
20+ private activatedRoute : ActivatedRoute ,
1721 ) { }
1822
23+ ngOnInit ( ) : void {
24+ this . activatedRoute . queryParams . subscribe ( ( { q } ) => this . currentValueSearch = q || '' ) ;
25+ }
26+
1927 changeVisibilitySidebar ( ) : void {
2028 const sidebarElement = document . querySelector ( '.sidebar' ) as HTMLElement ;
2129 sidebarElement . classList . toggle ( 'closed' ) ;
@@ -34,4 +42,9 @@ export class HeaderComponent {
3442 focusInputSearch ( ) : void {
3543 this . inputSearch . nativeElement . classList . toggle ( 'focus' ) ;
3644 }
45+
46+ goToSearch ( query : string ) : void {
47+ if ( query ) this . router . navigate ( [ '/search' ] , { queryParams : { q : query } } ) ;
48+ }
49+
3750}
0 commit comments