Use vote pending state as subject

Fixes an issue where the vote pending state was not updating correctly
when using state changes over the choice service
This commit is contained in:
Sean 2021-06-23 13:58:21 +02:00
parent 382fcf4a67
commit 235bbf6c0d
3 changed files with 11 additions and 10 deletions

View File

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

View File

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

View File

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