Merge pull request #6127 from tsiegleauq/stop-vote-show-please-wait

Use vote pending state as subject
This commit is contained in:
Emanuel Schütze 2021-06-23 16:18:38 +02:00 committed by GitHub
commit a14ab8c5e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View File

@ -49,14 +49,14 @@
mat-stroked-button mat-stroked-button
[ngClass]="pollStateActions[poll.state].css" [ngClass]="pollStateActions[poll.state].css"
(click)="nextPollState()" (click)="nextPollState()"
[disabled]="stateChangePending" [disabled]="stateChangePendingObservable | async"
> >
<mat-icon> {{ pollStateActions[poll.state].icon }}</mat-icon> <mat-icon> {{ pollStateActions[poll.state].icon }}</mat-icon>
<span class="next-state-label"> <span class="next-state-label">
<ng-container *ngIf="!stateChangePending"> <ng-container *ngIf="!(stateChangePendingObservable | async)">
{{ poll.nextStateActionVerbose | translate }} {{ poll.nextStateActionVerbose | translate }}
</ng-container> </ng-container>
<ng-container *ngIf="stateChangePending"> <ng-container *ngIf="stateChangePendingObservable | async">
{{ 'In progress, please wait...' | translate }} {{ 'In progress, please wait...' | translate }}
</ng-container> </ng-container>
</span> </span>

View File

@ -51,14 +51,14 @@
mat-stroked-button mat-stroked-button
[ngClass]="pollStateActions[poll.state].css" [ngClass]="pollStateActions[poll.state].css"
(click)="nextPollState()" (click)="nextPollState()"
[disabled]="stateChangePending" [disabled]="stateChangePendingObservable | async"
> >
<mat-icon> {{ pollStateActions[poll.state].icon }}</mat-icon> <mat-icon> {{ pollStateActions[poll.state].icon }}</mat-icon>
<span class="next-state-label"> <span class="next-state-label">
<ng-container *ngIf="!stateChangePending"> <ng-container *ngIf="!(stateChangePendingObservable | async)">
{{ poll.nextStateActionVerbose | translate }} {{ poll.nextStateActionVerbose | translate }}
</ng-container> </ng-container>
<ng-container *ngIf="stateChangePending"> <ng-container *ngIf="stateChangePendingObservable | async">
{{ 'In progress, please wait...' | translate }} {{ 'In progress, please wait...' | translate }}
</ng-container> </ng-container>
</span> </span>

View File

@ -3,7 +3,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject, Subject } from 'rxjs';
import { BasePollDialogService } from 'app/core/ui-services/base-poll-dialog.service'; import { BasePollDialogService } from 'app/core/ui-services/base-poll-dialog.service';
import { ChoiceService } from 'app/core/ui-services/choice.service'; import { ChoiceService } from 'app/core/ui-services/choice.service';
@ -19,7 +19,8 @@ export abstract class BasePollComponent<
V extends ViewBasePoll, V extends ViewBasePoll,
S extends PollService S extends PollService
> extends BaseViewComponentDirective { > extends BaseViewComponentDirective {
public stateChangePending = false; private stateChangePendingSubject = new Subject<boolean>();
public readonly stateChangePendingObservable = this.stateChangePendingSubject.asObservable();
public chartDataSubject: BehaviorSubject<ChartData> = new BehaviorSubject([]); public chartDataSubject: BehaviorSubject<ChartData> = new BehaviorSubject([]);
@ -74,12 +75,12 @@ export abstract class BasePollComponent<
} }
private async changeState(targetState: PollState): Promise<void> { private async changeState(targetState: PollState): Promise<void> {
this.stateChangePending = true; this.stateChangePendingSubject.next(true);
this.repo this.repo
.changePollState(this._poll, targetState) .changePollState(this._poll, targetState)
.catch(this.raiseError) .catch(this.raiseError)
.finally(() => { .finally(() => {
this.stateChangePending = false; this.stateChangePendingSubject.next(false);
}); });
} }