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

80 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-03-22 20:13:11 +01:00
import {ChangeDetectionStrategy, Component, HostListener, OnInit} from '@angular/core';
import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services';
2021-03-22 20:13:11 +01:00
import {SwUpdate} from '@angular/service-worker';
2020-10-30 16:16:05 +01:00
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
2020-10-30 16:16:05 +01:00
})
2021-03-22 20:13:11 +01:00
export class AppComponent implements OnInit {
title = 'CICADA';
2020-11-08 07:31:52 +01:00
readyStateTarget: number = 3;
readyState: number = 0;
mediaQuery = window.matchMedia('(max-width: 768px)');
2020-11-08 07:31:52 +01:00
constructor(
private authService: AuthService,
private tokenService: TokenService,
private transactionService: TransactionService,
private loggingService: LoggingService,
2021-03-22 20:13:11 +01:00
private swUpdate: SwUpdate
) {
(async () => {
await this.authService.mutableKeyStore.loadKeyring();
await this.authService.getPublicKeys();
this.loggingService.sendInfoLevelMessage(await this.tokenService.getTokens());
})();
this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery);
2020-11-08 07:31:52 +01:00
}
2021-03-22 20:13:11 +01:00
ngOnInit(): void {
if (!this.swUpdate.isEnabled) {
this.swUpdate.available.subscribe(() => {
if (confirm('New Version available. Load New Version?')) {
window.location.reload();
}
});
}
}
// 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');
}
2020-11-08 07:31:52 +01:00
}
}
@HostListener('window:cic_transfer', ['$event'])
async cicTransfer(event: CustomEvent): Promise<void> {
2020-11-08 07:31:52 +01:00
const transaction = event.detail.tx;
await this.transactionService.setTransaction(transaction, 100);
2020-11-08 07:31:52 +01:00
}
@HostListener('window:cic_convert', ['$event'])
async cicConvert(event: CustomEvent): Promise<void> {
2020-11-08 07:31:52 +01:00
const conversion = event.detail.tx;
await this.transactionService.setConversion(conversion, 100);
2020-11-08 07:31:52 +01:00
}
2020-10-30 16:16:05 +01:00
}