2023-08-28 17:42:32 +09:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, HostListener, OnDestroy } from '@angular/core';
|
2023-08-17 18:51:39 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { ApiService } from '../../services/api.service';
|
|
|
|
import { MenuGroup } from '../../interfaces/services.interface';
|
2023-08-20 08:11:55 +02:00
|
|
|
import { StorageService } from '../../services/storage.service';
|
2023-08-22 08:35:10 +02:00
|
|
|
import { Router, NavigationStart } from '@angular/router';
|
2023-08-21 08:57:27 +02:00
|
|
|
import { StateService } from '../../services/state.service';
|
2023-08-17 18:51:39 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-menu',
|
|
|
|
templateUrl: './menu.component.html',
|
|
|
|
styleUrls: ['./menu.component.scss']
|
|
|
|
})
|
|
|
|
|
2023-08-28 17:42:32 +09:00
|
|
|
export class MenuComponent implements OnInit, OnDestroy {
|
2023-08-27 12:52:58 +02:00
|
|
|
@Input() navOpen: boolean = false;
|
2023-08-20 22:53:33 +02:00
|
|
|
@Output() loggedOut = new EventEmitter<boolean>();
|
2023-08-27 12:52:58 +02:00
|
|
|
@Output() menuToggled = new EventEmitter<boolean>();
|
|
|
|
|
2023-08-17 18:51:39 +02:00
|
|
|
userMenuGroups$: Observable<MenuGroup[]> | undefined;
|
2023-08-18 18:04:40 +02:00
|
|
|
userAuth: any | undefined;
|
2023-08-21 08:57:27 +02:00
|
|
|
isServicesPage = false;
|
2023-08-17 18:51:39 +02:00
|
|
|
|
|
|
|
constructor(
|
2023-08-20 08:11:55 +02:00
|
|
|
private apiService: ApiService,
|
2023-08-20 22:53:33 +02:00
|
|
|
private storageService: StorageService,
|
2023-08-21 08:57:27 +02:00
|
|
|
private router: Router,
|
|
|
|
private stateService: StateService
|
2023-08-17 18:51:39 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2023-08-20 08:11:55 +02:00
|
|
|
this.userAuth = this.storageService.getAuth();
|
2023-08-28 09:29:13 +02:00
|
|
|
|
2023-08-21 08:57:27 +02:00
|
|
|
if (this.stateService.env.GIT_COMMIT_HASH_MEMPOOL_SPACE) {
|
|
|
|
this.userMenuGroups$ = this.apiService.getUserMenuGroups$();
|
|
|
|
}
|
2023-08-20 22:53:33 +02:00
|
|
|
|
2023-08-21 08:57:27 +02:00
|
|
|
this.isServicesPage = this.router.url.includes('/services/');
|
2023-08-22 08:35:10 +02:00
|
|
|
this.router.events.subscribe((event) => {
|
|
|
|
if (event instanceof NavigationStart) {
|
|
|
|
if (!this.isServicesPage) {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.toggleMenu(false);
|
2023-08-22 08:35:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-08-20 22:53:33 +02:00
|
|
|
}
|
|
|
|
|
2023-08-27 12:52:58 +02:00
|
|
|
toggleMenu(toggled: boolean) {
|
|
|
|
this.navOpen = toggled;
|
|
|
|
this.menuToggled.emit(toggled);
|
|
|
|
}
|
|
|
|
|
2023-08-20 22:53:33 +02:00
|
|
|
isSmallScreen() {
|
|
|
|
return window.innerWidth <= 767.98;
|
2023-08-17 18:51:39 +02:00
|
|
|
}
|
2023-08-17 22:13:06 +02:00
|
|
|
|
|
|
|
logout(): void {
|
2023-08-21 15:01:31 +02:00
|
|
|
this.apiService.logout$().subscribe(() => {
|
|
|
|
this.loggedOut.emit(true);
|
|
|
|
if (this.stateService.env.GIT_COMMIT_HASH_MEMPOOL_SPACE) {
|
|
|
|
this.userMenuGroups$ = this.apiService.getUserMenuGroups$();
|
|
|
|
this.router.navigateByUrl('/');
|
|
|
|
}
|
|
|
|
});
|
2023-08-18 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-21 22:08:25 +02:00
|
|
|
onLinkClick(link) {
|
2023-08-22 08:35:10 +02:00
|
|
|
if (!this.isServicesPage || this.isSmallScreen()) {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.toggleMenu(false);
|
2023-08-22 08:35:10 +02:00
|
|
|
}
|
2023-08-21 22:08:25 +02:00
|
|
|
this.router.navigateByUrl(link);
|
2023-08-20 22:53:33 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 20:00:32 +09:00
|
|
|
hamburgerClick() {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.toggleMenu(!this.navOpen);
|
2023-08-23 19:59:54 +09:00
|
|
|
this.stateService.menuOpen$.next(this.navOpen);
|
2023-08-17 22:13:06 +02:00
|
|
|
}
|
2023-08-20 22:54:12 +02:00
|
|
|
|
2023-08-21 22:08:25 +02:00
|
|
|
@HostListener('window:click', ['$event'])
|
|
|
|
onClick(event) {
|
2023-08-23 16:17:07 +02:00
|
|
|
const isServicesPageOnMobile = this.isServicesPage && this.isSmallScreen();
|
2023-08-22 08:35:10 +02:00
|
|
|
const cssClasses = event.target.className;
|
2023-08-23 16:17:07 +02:00
|
|
|
|
2023-08-22 14:59:23 +02:00
|
|
|
if (!cssClasses.indexOf) { // Click on chart or non html thingy, close the menu
|
2023-08-23 16:17:07 +02:00
|
|
|
if (!this.isServicesPage || isServicesPageOnMobile) {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.toggleMenu(false);
|
2023-08-23 16:17:07 +02:00
|
|
|
}
|
2023-08-22 14:59:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-22 08:35:10 +02:00
|
|
|
const isHamburger = cssClasses.indexOf('profile_image') !== -1;
|
|
|
|
const isMenu = cssClasses.indexOf('menu-click') !== -1;
|
2023-08-22 14:59:23 +02:00
|
|
|
if (!isHamburger && !isMenu && (!this.isServicesPage || isServicesPageOnMobile)) {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.toggleMenu(false);
|
2023-08-20 22:54:12 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-28 17:42:32 +09:00
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.stateService.menuOpen$.next(false);
|
|
|
|
}
|
2023-08-17 18:51:39 +02:00
|
|
|
}
|