2025-11-11 10:52:30 +07:00
|
|
|
import { Component, HostListener, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-sidebar',
|
|
|
|
|
standalone: false,
|
|
|
|
|
templateUrl: './sidebar.component.html',
|
2025-11-23 20:12:01 +07:00
|
|
|
styleUrls: ['./sidebar.component.css']
|
2025-11-11 10:52:30 +07:00
|
|
|
})
|
|
|
|
|
export class SidebarComponent implements OnInit {
|
2025-11-23 20:12:01 +07:00
|
|
|
isOpen = true;
|
|
|
|
|
isMobile = false;
|
2025-11-11 10:52:30 +07:00
|
|
|
|
|
|
|
|
constructor(private router: Router) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.checkDevice();
|
|
|
|
|
window.addEventListener('resize', () => this.checkDevice());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@HostListener('window:resize')
|
|
|
|
|
checkDevice() {
|
|
|
|
|
this.isMobile = window.innerWidth <= 768;
|
|
|
|
|
if (this.isMobile) {
|
2025-11-23 20:12:01 +07:00
|
|
|
this.isOpen = false;
|
2025-11-11 10:52:30 +07:00
|
|
|
} else {
|
2025-11-23 20:12:01 +07:00
|
|
|
this.isOpen = true;
|
2025-11-11 10:52:30 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleSidebar() {
|
2025-11-23 20:12:01 +07:00
|
|
|
this.isOpen = !this.isOpen;
|
2025-11-11 10:52:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navigate(path: string) {
|
|
|
|
|
this.router.navigate([path]);
|
2025-11-23 20:12:01 +07:00
|
|
|
if (this.isMobile) {
|
|
|
|
|
this.isOpen = false;
|
|
|
|
|
}
|
2025-11-11 10:52:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
|
localStorage.removeItem('access_token');
|
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
|
}
|
|
|
|
|
}
|