All files / src/app/components/global-error global-error.component.ts

18.18% Statements 2/11
0% Branches 0/4
25% Functions 1/4
10% Lines 1/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                    59x                                                      
import { NgIf } from '@angular/common';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { interval, Subject, takeUntil } from 'rxjs';
 
@Component({
  selector: 'app-global-error',
  imports: [NgIf],
  templateUrl: './global-error.component.html',
  styleUrl: './global-error.component.scss'
})
export class GlobalErrorComponent implements OnInit, OnDestroy{
 
  @Input() nextRequest: number;
  nextPingWait: number;
  image: string;
  images = ['towing', 'alien-invasion', 'server-down'];
  private destroy$ = new Subject<void>();
 
  ngOnInit(){
    this.image =  'assets/svg/'+ this.images[Math.floor(Math.random() * this.images.length)] + '.svg';
 
    interval(200)
    .pipe(takeUntil(this.destroy$))
    .subscribe(() => {
      this.nextPingWait = Math.round((this.nextRequest - Date.now() ) *0.001);
      if (this.nextPingWait < 0){
        this.nextPingWait = 0;
      }
    });
  }
 
  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }
 
}