Merge branch 'master' into spencer/linting
# Conflicts: # package-lock.json # src/app/app.component.ts # src/app/app.module.ts # src/app/shared/shared.module.ts
This commit is contained in:
@@ -1 +1,2 @@
|
||||
<app-network-status></app-network-status>
|
||||
<router-outlet (activate)="onResize(mediaQuery)"></router-outlet>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
TransactionService,
|
||||
} from '@app/_services';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import {SwUpdate} from '@angular/service-worker';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -13,7 +14,7 @@ import { catchError } from 'rxjs/operators';
|
||||
styleUrls: ['./app.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AppComponent {
|
||||
export class AppComponent implements OnInit {
|
||||
title = 'CICADA';
|
||||
readyStateTarget: number = 3;
|
||||
readyState: number = 0;
|
||||
@@ -23,7 +24,8 @@ export class AppComponent {
|
||||
private authService: AuthService,
|
||||
private transactionService: TransactionService,
|
||||
private loggingService: LoggingService,
|
||||
private errorDialogService: ErrorDialogService
|
||||
private errorDialogService: ErrorDialogService,
|
||||
private swUpdate: SwUpdate
|
||||
) {
|
||||
(async () => {
|
||||
try {
|
||||
@@ -46,6 +48,16 @@ export class AppComponent {
|
||||
this.onResize(this.mediaQuery);
|
||||
}
|
||||
|
||||
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: HTMLElement = document.getElementById('sidebar');
|
||||
|
||||
@@ -14,6 +14,7 @@ import { LoggerModule } from 'ngx-logger';
|
||||
import { environment } from '@src/environments/environment';
|
||||
import { ErrorInterceptor, HttpConfigInterceptor, LoggingInterceptor } from '@app/_interceptors';
|
||||
import { MutablePgpKeyStore } from '@app/_pgp';
|
||||
import { ServiceWorkerModule } from '@angular/service-worker';
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent],
|
||||
@@ -31,6 +32,7 @@ import { MutablePgpKeyStore } from '@app/_pgp';
|
||||
serverLoggingUrl: `${environment.loggingUrl}/api/logs/`,
|
||||
disableConsoleLogging: false,
|
||||
}),
|
||||
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
|
||||
],
|
||||
providers: [
|
||||
AuthGuard,
|
||||
|
||||
13
src/app/shared/network-status/network-status.component.html
Normal file
13
src/app/shared/network-status/network-status.component.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
<h1 class="navbar-brand">
|
||||
<div *ngIf="noInternetConnection; then offlineBlock else onlineBlock"></div>
|
||||
<ng-template #offlineBlock>
|
||||
<strong style="color: red;">OFFLINE </strong>
|
||||
<img width="20rem" src="assets/images/no-wifi.svg" alt="Internet Disconnected">
|
||||
</ng-template>
|
||||
<ng-template #onlineBlock>
|
||||
<strong style="color: lawngreen;">ONLINE </strong>
|
||||
<img width="20rem" src="assets/images/wifi.svg" alt="Internet Connected">
|
||||
</ng-template>
|
||||
</h1>
|
||||
</nav>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NetworkStatusComponent } from './network-status.component';
|
||||
|
||||
describe('NetworkStatusComponent', () => {
|
||||
let component: NetworkStatusComponent;
|
||||
let fixture: ComponentFixture<NetworkStatusComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ NetworkStatusComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NetworkStatusComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
30
src/app/shared/network-status/network-status.component.ts
Normal file
30
src/app/shared/network-status/network-status.component.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-network-status',
|
||||
templateUrl: './network-status.component.html',
|
||||
styleUrls: ['./network-status.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class NetworkStatusComponent implements OnInit {
|
||||
noInternetConnection: boolean = !navigator.onLine;
|
||||
|
||||
constructor(
|
||||
private cdr: ChangeDetectorRef,
|
||||
) {
|
||||
this.handleNetworkChange();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
handleNetworkChange(): void {
|
||||
setTimeout(() => {
|
||||
if (!navigator.onLine !== this.noInternetConnection) {
|
||||
this.noInternetConnection = !navigator.onLine;
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
this.handleNetworkChange();
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { TokenRatioPipe } from '@app/shared/_pipes/token-ratio.pipe';
|
||||
import { ErrorDialogComponent } from '@app/shared/error-dialog/error-dialog.component';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { SafePipe } from '@app/shared/_pipes/safe.pipe';
|
||||
import { NetworkStatusComponent } from './network-status/network-status.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -22,6 +23,7 @@ import { SafePipe } from '@app/shared/_pipes/safe.pipe';
|
||||
TokenRatioPipe,
|
||||
ErrorDialogComponent,
|
||||
SafePipe,
|
||||
NetworkStatusComponent
|
||||
],
|
||||
exports: [
|
||||
TopbarComponent,
|
||||
@@ -30,6 +32,7 @@ import { SafePipe } from '@app/shared/_pipes/safe.pipe';
|
||||
MenuSelectionDirective,
|
||||
TokenRatioPipe,
|
||||
SafePipe,
|
||||
NetworkStatusComponent
|
||||
],
|
||||
imports: [CommonModule, RouterModule, MatIconModule, MatDialogModule],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user