edit-identity.component.ts raw

   1  import { Component, inject, OnInit } from '@angular/core';
   2  import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
   3  import { IconButtonComponent, Identity_DECRYPTED, StorageService } from '@common';
   4  
   5  @Component({
   6    selector: 'app-edit-identity',
   7    templateUrl: './edit-identity.component.html',
   8    styleUrl: './edit-identity.component.scss',
   9    imports: [RouterOutlet, IconButtonComponent],
  10  })
  11  export class EditIdentityComponent implements OnInit {
  12    identity?: Identity_DECRYPTED;
  13    previousRoute?: string;
  14  
  15    readonly #activatedRoute = inject(ActivatedRoute);
  16    readonly #storage = inject(StorageService);
  17    readonly #router = inject(Router);
  18  
  19    constructor() {
  20      // Must be called in the constructor and NOT in ngOnInit.
  21      this.previousRoute = this.#router
  22        .getCurrentNavigation()
  23        ?.previousNavigation?.extractedUrl.toString();
  24    }
  25  
  26    ngOnInit(): void {
  27      const selectedIdentityId = this.#activatedRoute.snapshot.params['id'];
  28      if (!selectedIdentityId) {
  29        return;
  30      }
  31  
  32      this.identity = this.#storage
  33        .getBrowserSessionHandler()
  34        .browserSessionData?.identities.find((x) => x.id === selectedIdentityId);
  35    }
  36  
  37    onClickCancel() {
  38      if (!this.previousRoute) {
  39        return;
  40      }
  41      this.#router.navigateByUrl(this.previousRoute);
  42    }
  43  }
  44