mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2025-05-14 10:49:19 +00:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import {Component, Input, OnInit} from '@angular/core';
|
|
import {ApiService} from "../../services/api.service";
|
|
import {Router} from "@angular/router";
|
|
|
|
|
|
@Component({
|
|
selector: 'app-top-bar',
|
|
templateUrl: './top-bar.component.html',
|
|
styleUrls: ['./top-bar.component.css']
|
|
})
|
|
export class TopBarComponent implements OnInit {
|
|
|
|
sidenav: any;
|
|
isLoggedIn: boolean;
|
|
searchQuery: string;
|
|
|
|
constructor(
|
|
private api: ApiService,
|
|
private router: Router
|
|
) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.api.getUserInfo().subscribe(data => {
|
|
console.log(data)
|
|
});
|
|
|
|
if (this.api.getSessionInfoFromLocalStorage().session_id != "") {
|
|
this.isLoggedIn = true;
|
|
}
|
|
}
|
|
|
|
logout(): void {
|
|
localStorage.setItem('session_id', '');
|
|
localStorage.setItem('session_key', '');
|
|
this.router.navigate(['/']);
|
|
}
|
|
|
|
getSearchedProducts(): void {
|
|
console.log(this.searchQuery);
|
|
this.redirectTo('/search', {queryParams: {q: this.searchQuery}});
|
|
}
|
|
|
|
redirectTo(uri: string, queryParams: object): void {
|
|
this.router.navigateByUrl('/', {skipLocationChange: true}).then(() =>
|
|
this.router.navigate([uri], queryParams));
|
|
}
|
|
}
|