import { Component, OnDestroy } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { SpinnerService } from '@core/services/spinner.service'; import { CommunicationsService } from '@features/communications/communications.service'; import { Communication } from '@features/communications/communications.typing'; import { Subscription } from 'rxjs'; import { ApplicationViewService } from '../application-view.service'; @Component({ selector: 'gc-communications-tab', templateUrl: './communications-tab.component.html', styleUrls: ['./communications-tab.component.scss'] }) export class CommunicationsTabComponent implements OnDestroy { applicationId = +this.activatedRoute.parent.snapshot.paramMap.get('id'); sub = new Subscription(); constructor ( private communicationsService: CommunicationsService, private activatedRoute: ActivatedRoute, private spinnerService: SpinnerService, private applicationViewService: ApplicationViewService ) { this.sub.add( this.applicationViewService.changesTo$('applicationViewMap') .subscribe(() => { this.updatePanel(); }) ); } get allComms () { return this.communicationsService.applicationCommunicationsMap[this.applicationId]; } get applicationViewMap () { return this.applicationViewService.applicationViewMap; } get isNomination () { return location.pathname.includes('nomination'); } async updatePanel () { this.spinnerService.startSpinner(); await this.communicationsService.getCommunicationsForApplication( this.applicationId, true ); this.spinnerService.stopSpinner(); } async addCommunication (comm: Communication) { this.spinnerService.startSpinner(); await this.communicationsService.addApplicationCommunication( comm, this.applicationId ); await this.updatePanel(); this.spinnerService.stopSpinner(); } async updateCommunication (comm: Communication) { this.spinnerService.startSpinner(); await this.communicationsService.updateApplicationCommunication( comm, this.applicationId ); await this.updatePanel(); this.spinnerService.stopSpinner(); } async removeCommunication (comm: Communication) { this.spinnerService.startSpinner(); await this.communicationsService.deleteApplicationCommunication( comm.joinCommunicationId ); await this.updatePanel(); this.spinnerService.stopSpinner(); } async sendInviteEmail (comm: Communication) { this.spinnerService.startSpinner(); await this.communicationsService.handleSendInviteEmail( comm, this.applicationId ); await this.updatePanel(); this.spinnerService.stopSpinner(); } ngOnDestroy () { this.sub.unsubscribe(); } }