From 235bbf6c0dcd7faa6dc113b8296fb5d334066ed5 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 23 Jun 2021 13:58:21 +0200 Subject: [PATCH] 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 --- .../assignment-poll/assignment-poll.component.html | 6 +++--- .../motion-poll/motion-poll/motion-poll.component.html | 6 +++--- .../src/app/site/polls/components/base-poll.component.ts | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/src/app/site/assignments/modules/assignment-poll/components/assignment-poll/assignment-poll.component.html b/client/src/app/site/assignments/modules/assignment-poll/components/assignment-poll/assignment-poll.component.html index c6f5f6986..ec813db7d 100644 --- a/client/src/app/site/assignments/modules/assignment-poll/components/assignment-poll/assignment-poll.component.html +++ b/client/src/app/site/assignments/modules/assignment-poll/components/assignment-poll/assignment-poll.component.html @@ -49,14 +49,14 @@ mat-stroked-button [ngClass]="pollStateActions[poll.state].css" (click)="nextPollState()" - [disabled]="stateChangePending" + [disabled]="stateChangePendingObservable | async" > {{ pollStateActions[poll.state].icon }} - + {{ poll.nextStateActionVerbose | translate }} - + {{ 'In progress, please wait...' | translate }} diff --git a/client/src/app/site/motions/modules/motion-poll/motion-poll/motion-poll.component.html b/client/src/app/site/motions/modules/motion-poll/motion-poll/motion-poll.component.html index c1e62a0ce..591fca700 100644 --- a/client/src/app/site/motions/modules/motion-poll/motion-poll/motion-poll.component.html +++ b/client/src/app/site/motions/modules/motion-poll/motion-poll/motion-poll.component.html @@ -51,14 +51,14 @@ mat-stroked-button [ngClass]="pollStateActions[poll.state].css" (click)="nextPollState()" - [disabled]="stateChangePending" + [disabled]="stateChangePendingObservable | async" > {{ pollStateActions[poll.state].icon }} - + {{ poll.nextStateActionVerbose | translate }} - + {{ 'In progress, please wait...' | translate }} diff --git a/client/src/app/site/polls/components/base-poll.component.ts b/client/src/app/site/polls/components/base-poll.component.ts index 240c8baf8..5e10a50d3 100644 --- a/client/src/app/site/polls/components/base-poll.component.ts +++ b/client/src/app/site/polls/components/base-poll.component.ts @@ -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(); + public readonly stateChangePendingObservable = this.stateChangePendingSubject.asObservable(); public chartDataSubject: BehaviorSubject = new BehaviorSubject([]); @@ -74,12 +75,12 @@ export abstract class BasePollComponent< } private async changeState(targetState: PollState): Promise { - this.stateChangePending = true; + this.stateChangePendingSubject.next(true); this.repo .changePollState(this._poll, targetState) .catch(this.raiseError) .finally(() => { - this.stateChangePending = false; + this.stateChangePendingSubject.next(false); }); }