All files / app/component/action/inline-button inline-button.component.ts

59.09% Statements 13/22
100% Branches 12/12
33.33% Functions 3/9
58.82% Lines 10/17

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 4288x 88x   88x 88x                   88x     9x   9x   9x 9x     4x                                
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { FakeLinkDirective } from '../../../directive/fake-link.directive';
import { catchError, Observable, of } from 'rxjs';
import { LoadingComponent } from '../../loading/loading.component';
import { ActionComponent } from '../action.component';
 
@Component({
  selector: 'app-inline-button',
  templateUrl: './inline-button.component.html',
  styleUrls: ['./inline-button.component.scss'],
  host: { 'class': 'action' },
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [FakeLinkDirective, LoadingComponent]
})
export class InlineButtonComponent extends ActionComponent {
 
  @Input()
  action: () => Observable<any|never> = () => of(null);
  @Input()
  minDelayMs = 1000;
 
  acting = false;
  minTimeout = false;
 
  override reset() {
    this.acting = false;
  }
 
  override active() {
    return this.acting;
  }
 
  act() {
    this.acting = true;
    this.minTimeout = true;
    setTimeout(() => this.minTimeout = false, this.minDelayMs);
    this.action().pipe(
      catchError(() => of(null)),
    ).subscribe(() => this.acting = false);
  }
}