From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:17:08 +0000 (-0700) Subject: Use progress bar for button delay X-Git-Tag: beta-1.6.1~68^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F415%2Fhead;p=thirdparty%2Fpaperless-ngx.git Use progress bar for button delay --- diff --git a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html index a55c0b00a3..19d907c82a 100644 --- a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html +++ b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html @@ -8,9 +8,12 @@

{{message}}

diff --git a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts index 10d32db436..ddf0bfd7ca 100644 --- a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts +++ b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core' import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' -import { Subject } from 'rxjs' +import { interval, Subject, switchMap, take } from 'rxjs' @Component({ selector: 'app-confirm-dialog', @@ -33,19 +33,28 @@ export class ConfirmDialogComponent { confirmButtonEnabled = true seconds = 0 + secondsTotal = 0 confirmSubject: Subject delayConfirm(seconds: number) { - this.confirmButtonEnabled = false + const refreshInterval = 0.15 // s + + this.secondsTotal = seconds this.seconds = seconds - setTimeout(() => { - if (this.seconds <= 1) { - this.confirmButtonEnabled = true - } else { - this.delayConfirm(seconds - 1) - } - }, 1000) + + interval(refreshInterval * 1000) + .pipe( + take(this.secondsTotal / refreshInterval + 2) // need 2 more for animation to complete after 0 + ) + .subscribe((count) => { + this.seconds = Math.max( + 0, + this.secondsTotal - refreshInterval * (count + 1) + ) + this.confirmButtonEnabled = + this.secondsTotal - refreshInterval * count < 0 + }) } cancel() {