import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation, } from '@angular/core'; import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav'; import { RouterOutlet } from '@angular/router'; import { FuseMediaWatcherService } from '@fuse/services/media-watcher'; import { Subject, takeUntil } from 'rxjs'; import { MailboxSidebarComponent } from './sidebar/sidebar.component'; @Component({ selector: 'mailbox', templateUrl: './mailbox.component.html', encapsulation: ViewEncapsulation.None, imports: [MatSidenavModule, MailboxSidebarComponent, RouterOutlet], }) export class MailboxComponent implements OnInit, OnDestroy { @ViewChild('drawer') drawer: MatDrawer; drawerMode: 'over' | 'side' = 'side'; drawerOpened: boolean = true; private _unsubscribeAll: Subject = new Subject(); /** * Constructor */ constructor(private _fuseMediaWatcherService: FuseMediaWatcherService) {} // ----------------------------------------------------------------------------------------------------- // @ Lifecycle hooks // ----------------------------------------------------------------------------------------------------- /** * On init */ ngOnInit(): void { // Subscribe to media changes this._fuseMediaWatcherService.onMediaChange$ .pipe(takeUntil(this._unsubscribeAll)) .subscribe(({ matchingAliases }) => { // Set the drawerMode and drawerOpened if the given breakpoint is active if (matchingAliases.includes('md')) { this.drawerMode = 'side'; this.drawerOpened = true; } else { this.drawerMode = 'over'; this.drawerOpened = false; } }); } /** * On destroy */ ngOnDestroy(): void { // Unsubscribe from all subscriptions this._unsubscribeAll.next(null); this._unsubscribeAll.complete(); } }