2024-03-07 18:32:04 +09:00
|
|
|
import { Component, OnInit, OnDestroy, Input, ViewChild } from '@angular/core';
|
2023-08-27 12:52:58 +02:00
|
|
|
import { Router } from '@angular/router';
|
2020-11-23 02:30:46 +07:00
|
|
|
import { Env, StateService } from '../../services/state.service';
|
2024-03-07 18:32:04 +09:00
|
|
|
import { Observable, merge, of, Subscription } from 'rxjs';
|
2022-09-21 17:23:45 +02:00
|
|
|
import { LanguageService } from '../../services/language.service';
|
|
|
|
import { EnterpriseService } from '../../services/enterprise.service';
|
2022-10-12 22:13:29 +00:00
|
|
|
import { NavigationService } from '../../services/navigation.service';
|
2023-08-18 17:56:07 +02:00
|
|
|
import { MenuComponent } from '../menu/menu.component';
|
2023-08-20 08:11:55 +02:00
|
|
|
import { StorageService } from '../../services/storage.service';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-master-page',
|
|
|
|
templateUrl: './master-page.component.html',
|
2020-08-02 16:00:08 +07:00
|
|
|
styleUrls: ['./master-page.component.scss'],
|
2020-02-16 22:15:07 +07:00
|
|
|
})
|
2024-03-07 18:32:04 +09:00
|
|
|
export class MasterPageComponent implements OnInit, OnDestroy {
|
2023-08-03 14:29:10 +09:00
|
|
|
@Input() headerVisible = true;
|
|
|
|
@Input() footerVisibleOverride: boolean | null = null;
|
|
|
|
|
2020-11-23 02:30:46 +07:00
|
|
|
env: Env;
|
2020-08-02 16:00:08 +07:00
|
|
|
network$: Observable<string>;
|
|
|
|
connectionState$: Observable<number>;
|
2020-02-16 22:15:07 +07:00
|
|
|
navCollapsed = false;
|
2020-10-09 13:56:43 +07:00
|
|
|
isMobile = window.innerWidth <= 767.98;
|
2021-02-18 13:34:05 +07:00
|
|
|
officialMempoolSpace = this.stateService.env.OFFICIAL_MEMPOOL_SPACE;
|
2022-01-10 15:50:21 +04:00
|
|
|
urlLanguage: string;
|
2022-07-21 19:58:12 +02:00
|
|
|
subdomain = '';
|
2022-10-12 22:13:29 +00:00
|
|
|
networkPaths: { [network: string]: string };
|
2023-05-11 11:38:57 -05:00
|
|
|
networkPaths$: Observable<Record<string, string>>;
|
|
|
|
footerVisible = true;
|
2023-08-21 17:04:17 +02:00
|
|
|
user: any = undefined;
|
2023-08-18 18:12:45 +02:00
|
|
|
servicesEnabled = false;
|
2023-08-27 12:52:58 +02:00
|
|
|
menuOpen = false;
|
2024-03-07 18:32:04 +09:00
|
|
|
|
|
|
|
enterpriseInfo: any;
|
|
|
|
enterpriseInfo$: Subscription;
|
2023-08-18 17:56:07 +02:00
|
|
|
|
|
|
|
@ViewChild(MenuComponent)
|
2023-08-27 12:52:58 +02:00
|
|
|
public menuComponent!: MenuComponent;
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
constructor(
|
2022-02-15 16:02:30 +09:00
|
|
|
public stateService: StateService,
|
2022-01-10 15:50:21 +04:00
|
|
|
private languageService: LanguageService,
|
2022-07-21 19:58:12 +02:00
|
|
|
private enterpriseService: EnterpriseService,
|
2022-10-12 22:13:29 +00:00
|
|
|
private navigationService: NavigationService,
|
2023-08-21 17:04:17 +02:00
|
|
|
private storageService: StorageService,
|
2023-08-27 12:52:58 +02:00
|
|
|
private router: Router,
|
2020-02-16 22:15:07 +07:00
|
|
|
) { }
|
|
|
|
|
2023-05-11 11:38:57 -05:00
|
|
|
ngOnInit(): void {
|
2020-11-23 02:30:46 +07:00
|
|
|
this.env = this.stateService.env;
|
2020-08-02 16:00:08 +07:00
|
|
|
this.connectionState$ = this.stateService.connectionState$;
|
|
|
|
this.network$ = merge(of(''), this.stateService.networkChanged$);
|
2022-01-10 15:50:21 +04:00
|
|
|
this.urlLanguage = this.languageService.getLanguageForUrl();
|
2022-07-21 19:58:12 +02:00
|
|
|
this.subdomain = this.enterpriseService.getSubdomain();
|
2022-10-12 22:13:29 +00:00
|
|
|
this.navigationService.subnetPaths.subscribe((paths) => {
|
|
|
|
this.networkPaths = paths;
|
2023-08-03 14:29:10 +09:00
|
|
|
if (this.footerVisibleOverride === null) {
|
|
|
|
if (paths.mainnet.indexOf('docs') > -1) {
|
|
|
|
this.footerVisible = false;
|
|
|
|
} else {
|
|
|
|
this.footerVisible = true;
|
|
|
|
}
|
2023-05-11 11:38:57 -05:00
|
|
|
} else {
|
2023-08-03 14:29:10 +09:00
|
|
|
this.footerVisible = this.footerVisibleOverride;
|
2023-05-11 11:38:57 -05:00
|
|
|
}
|
2022-10-12 22:13:29 +00:00
|
|
|
});
|
2024-03-07 18:32:04 +09:00
|
|
|
this.enterpriseInfo$ = this.enterpriseService.info$.subscribe(info => {
|
|
|
|
this.enterpriseInfo = info;
|
|
|
|
});
|
2023-08-18 17:56:07 +02:00
|
|
|
|
2023-08-18 18:12:45 +02:00
|
|
|
this.servicesEnabled = this.officialMempoolSpace && this.stateService.env.ACCELERATOR === true && this.stateService.network === '';
|
2023-08-18 18:33:09 +02:00
|
|
|
this.refreshAuth();
|
2023-08-27 12:52:58 +02:00
|
|
|
|
|
|
|
const isServicesPage = this.router.url.includes('/services/');
|
|
|
|
this.menuOpen = isServicesPage && !this.isSmallScreen();
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
2024-03-07 18:32:04 +09:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.enterpriseInfo$) {
|
|
|
|
this.enterpriseInfo$.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 22:15:07 +07:00
|
|
|
collapse(): void {
|
|
|
|
this.navCollapsed = !this.navCollapsed;
|
|
|
|
}
|
2021-08-18 21:48:12 +05:30
|
|
|
|
2023-08-27 12:52:58 +02:00
|
|
|
isSmallScreen() {
|
|
|
|
return window.innerWidth <= 767.98;
|
|
|
|
}
|
|
|
|
|
2023-05-11 11:38:57 -05:00
|
|
|
onResize(): void {
|
2023-08-27 12:52:58 +02:00
|
|
|
this.isMobile = this.isSmallScreen();
|
2021-08-18 21:48:12 +05:30
|
|
|
}
|
2023-06-09 19:03:47 -04:00
|
|
|
|
|
|
|
brandClick(e): void {
|
|
|
|
this.stateService.resetScroll$.next(true);
|
|
|
|
}
|
2023-08-18 17:56:07 +02:00
|
|
|
|
2023-08-20 08:11:55 +02:00
|
|
|
onLoggedOut(): void {
|
2023-08-18 18:33:09 +02:00
|
|
|
this.refreshAuth();
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshAuth(): void {
|
2023-08-28 09:29:13 +02:00
|
|
|
this.user = this.storageService.getAuth()?.user ?? null;
|
2023-08-18 18:33:09 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 11:50:47 +02:00
|
|
|
hamburgerClick(event): void {
|
2023-08-18 17:56:07 +02:00
|
|
|
if (this.menuComponent) {
|
2023-08-23 20:00:32 +09:00
|
|
|
this.menuComponent.hamburgerClick();
|
2023-08-27 12:52:58 +02:00
|
|
|
this.menuOpen = this.menuComponent.navOpen;
|
2023-08-23 11:50:47 +02:00
|
|
|
event.stopPropagation();
|
2023-08-18 17:56:07 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-27 12:52:58 +02:00
|
|
|
|
|
|
|
menuToggled(isOpen: boolean): void {
|
|
|
|
this.menuOpen = isOpen;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|