All files / app/components/page-cv/cv-contact-info cv-contact-info.component.ts

100% Statements 23/23
100% Branches 0/0
100% Functions 6/6
100% Lines 23/23

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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104                                          1x       54x   54x   54x   54x   54x   54x   54x                   54x 54x 54x   54x 54x                       38x                   27x 23x 23x 23x 23x 23x   23x                   57x                 47x      
import { CommonModule } from '@angular/common';
import { Component, ElementRef, OnDestroy, ViewChild } from '@angular/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { of } from 'rxjs';
import { ComponentWithText } from 'src/app/interfaces/ComponentWithText';
import { TextService } from 'src/app/services/db/text/text.service';
import { PreloaderService } from 'src/app/services/preloader/preloader.service';
import { Preloaders } from 'src/app/services/preloader/preloaders/preloaders';
import { VisibleToLoadTextService } from 'src/app/services/visibletoloadtext/visible-to-load-text.service';
 
/**
 * Contact info component, containing basic contact info such as phone number,
 * email and a quick review of my name and profile.
 */
@Component({
  selector: 'app-cv-contact-info',
  templateUrl: './cv-contact-info.component.html',
  styleUrls: ['./cv-contact-info.component.css'],
  standalone: true,
  imports: [CommonModule, MatProgressSpinnerModule],
})
export class CvContactInfoComponent implements ComponentWithText, OnDestroy {
  /** The main div element of the component. */
  @ViewChild('mainDiv') mainDiv!: ElementRef<HTMLElement>;
  /** Text containing the name label. */
  name = of('');
  /** Text containing the name. */
  sj = of('');
  /** Text containing the profile label. */
  profile = of('');
  /** Text containing the profile. */
  fsDev = of('');
  /** Text containing the email label. */
  email = of('');
  /** Text containing the phone label. */
  phone = of('');
  /** Preloader for texts. */
  loaderTexts = Preloaders.TEXTS;
 
  /**
   * Contact info component constructor.
   *
   * @param textService The {@link TextService}
   * @param visibleToLoadTextService The {@link VisibleToLoadTextService}
   * @param preloader The {@link PreloaderService}
   */
  constructor(
    private textService: TextService,
    public visibleToLoadTextService: VisibleToLoadTextService,
    public preloader: PreloaderService
  ) {
    setTimeout(() => {
      this.visibleToLoadTextService.subscribe(this);
    }, 0);
  }
 
  /**
   * Update the component's texts when the language is updated. See
   * {@link VisibleToLoadTextService}. The subscriber design pattern is used and
   * this function is used when the service notifies its subscribers to update
   * the text contents after a language change. Uses {@link TextService} to get
   * those contents from the database.
   */
  updateTexts(): void {
    this.textService
      .getMulti([
        'about-name-field',
        'sylvain-janet',
        'about-profile-field',
        'occupation-fullstack-dev',
        'about-email-field',
        'about-phone-field',
      ])
      .subscribe((r) => {
        this.name = of(r[0]);
        this.sj = of(r[1]);
        this.profile = of(r[2]);
        this.fsDev = of(r[3]);
        this.email = of(r[4]);
        this.phone = of(r[5]);
 
        this.visibleToLoadTextService.textLoaded(this);
      });
  }
 
  /**
   * On destroy, the component has to be unsubscribed rom the
   * {@link VisibleToLoadTextService} to avoid having the service try to notify a
   * destroyed subscriber.
   */
  ngOnDestroy(): void {
    this.visibleToLoadTextService.unsubscribe(this);
  }
 
  /**
   * Get the main component element.
   *
   * @returns The element.
   */
  getElement(): ElementRef<HTMLElement> {
    return this.mainDiv;
  }
}