File

projects/prestations-ng/src/foehn-page/foehn-transmit-waiting-modal/foehn-transmit-waiting-modal.service.ts

Index

Properties
Methods

Methods

modalVisibilityObservable
modalVisibilityObservable()
Returns : Observable<boolean>
toggleModalVisibility
toggleModalVisibility(isVisible: boolean)
Parameters :
Name Type Optional
isVisible boolean No
Returns : void

Properties

Private showModalDelayTimer
Type : any
Private toggleModalBehaviorSubject
Default value : new BehaviorSubject<boolean>(false)
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';

// Delay 2s because most transmit actions are done in less
export const TRANSMIT_WAITING_MODAL_DELAY_IN_MILLISECONDS = 2000;

@Injectable({
    providedIn: 'root'
})
export class FoehnTransmitWaitingModalService {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    private showModalDelayTimer: any;

    private toggleModalBehaviorSubject = new BehaviorSubject<boolean>(false);

    modalVisibilityObservable(): Observable<boolean> {
        return this.toggleModalBehaviorSubject.asObservable();
    }

    toggleModalVisibility(isVisible: boolean): void {
        clearTimeout(this.showModalDelayTimer);

        if (isVisible) {
            this.showModalDelayTimer = setTimeout(() => {
                this.toggleModalBehaviorSubject.next(true);
            }, TRANSMIT_WAITING_MODAL_DELAY_IN_MILLISECONDS);

            return;
        }

        this.toggleModalBehaviorSubject.next(false);
    }
}

results matching ""

    No results matching ""