cic-staff-client/src/app/app.component.ts

67 lines
2.2 KiB
TypeScript

import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services';
import {NGXLogger} from 'ngx-logger';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {
title = 'CICADA';
readyStateTarget: number = 3;
readyState: number = 0;
mediaQuery = window.matchMedia('(max-width: 768px)');
constructor(
private authService: AuthService,
private tokenService: TokenService,
private transactionService: TransactionService,
private logger: NGXLogger,
private loggingService: LoggingService,
) {
this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then());
this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r));
this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery);
}
// Load resize
onResize(e): void {
const sidebar = document.getElementById('sidebar');
const content = document.getElementById('content');
const sidebarCollapse = document.getElementById('sidebarCollapse');
if (sidebarCollapse?.classList.contains('active')) {
sidebarCollapse?.classList.remove('active');
}
if (e.matches) {
if (!sidebar?.classList.contains('active')) {
sidebar?.classList.add('active');
}
if (!content?.classList.contains('active')) {
content?.classList.add('active');
}
} else {
if (sidebar?.classList.contains('active')) {
sidebar?.classList.remove('active');
}
if (content?.classList.contains('active')) {
content?.classList.remove('active');
}
}
}
@HostListener('window:cic_transfer', ['$event'])
cicTransfer(event: CustomEvent): void {
const transaction = event.detail.tx;
this.transactionService.setTransaction(transaction, 100).then();
}
@HostListener('window:cic_convert', ['$event'])
cicConvert(event: CustomEvent): void {
const conversion = event.detail.tx;
this.transactionService.setConversion(conversion, 100).then();
}
}