All files / navbar navbar.component.ts

86.66% Statements 13/15
100% Branches 0/0
83.33% Functions 5/6
86.66% Lines 13/15

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                      1x 6x   6x   6x   6x             1x                         6x   6x   6x   6x     1x       1x       1x                                
import { ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output } from '@angular/core';
import { Router } from '@angular/router';
import { IRouterButton, routerButton, WINDOW } from '@app/client-util';
 
@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  standalone: false,
})
export class AppNavbarComponent {
  private readonly router = inject(Router);
 
  private readonly win = inject(WINDOW);
 
  @Input() public appName: string | null = null;
 
  @Input() public logoSrc: string | null = 'assets/svg/logo.svg';
 
  @Input() public buttons: IRouterButton[] = [
    routerButton(
      'Home',
      'home',
      () =>
        this.router.isActive('', {
          matrixParams: 'ignored',
          queryParams: 'ignored',
          paths: 'exact',
          fragment: 'ignored',
        }),
      [{ outlets: { primary: [''] } }],
    ),
  ];
 
  /**
   * This subscription is needed to trigger change detection on router events so that the nav buttons state updates.
   */
  public readonly routerEvents$ = this.router.events;
 
  @Output() public readonly navButtonClicked = new EventEmitter<undefined>();
 
  @Output() public readonly navigatedBack = new EventEmitter<undefined>();
 
  @Output() public readonly navigatedForward = new EventEmitter<undefined>();
 
  public navButtonClick(): void {
    this.navButtonClicked.emit();
  }
 
  public navigateBack(): void {
    this.navigatedBack.emit();
  }
 
  public navigateForward(): void {
    this.navigatedForward.emit();
  }
 
  public openNavigator(): void {
    const event = new KeyboardEvent('keydown', {
      key: '~',
      code: 'Backquote',
      ctrlKey: true,
      shiftKey: true,
      bubbles: true,
      cancelable: true,
    });
 
    this.win.dispatchEvent(event);
  }
}