Skip to content

Commit

Permalink
Fix vote components using wrong change detection strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel committed Jun 27, 2024
1 parent 0a160f2 commit 1af1e58
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h4 *ngIf="delegation" class="poll-delegation-title">
}"
>
<div *ngIf="showAvailableVotes" class="grid-name-area"></div>
<b *ngIf="!showAvailableVotes" class="grid-name-area">
<b *ngIf="!showAvailableVotes && poll.option_ids" class="grid-name-area">
{{ poll.option_ids.length }} {{ optionPluralLabel | translate }}
</b>
<b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
this._canVoteForSubjectMap[+key].next(this.canVote(this._delegationsMap[+key]));
}

this.cd.markForCheck();
this._isReady = true;
this.cd.markForCheck();
}
}),
this.translate.onLangChange.subscribe(() => {
Expand Down Expand Up @@ -423,19 +423,10 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
}
}

private createVotingDataObjects(): void {
this.voteRequestData[this.user.id] = { value: {} } as VotingData;
this.alreadyVoted[this.user.id] = this.poll.hasVoted;
this.deliveringVote[this.user.id] = false;

if (this.delegations) {
this.setupDelegations();
}
}

protected updatePoll(): void {
this.setupHasVotedSubscription();
this.defineVoteOptions();
this.cd.markForCheck();
}

private setupHasVotedSubscription(): void {
Expand All @@ -451,6 +442,8 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
for (const key of Object.keys(this._canVoteForSubjectMap)) {
this._canVoteForSubjectMap[+key].next(this.canVote(this._delegationsMap[+key]));
}

this.cd.markForCheck();
})
);
}
Expand Down Expand Up @@ -486,7 +479,7 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
};

for (const option of this.voteOptions) {
if (this.poll.pollmethod.includes(option.vote)) {
if (this.poll.pollmethod?.includes(option.vote)) {
this.voteActions.push(option);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { marker as _ } from '@colsen1991/ngx-translate-extract-marker';
import { PollMethod } from 'src/app/domain/models/poll/poll-constants';
import { VoteValue } from 'src/app/domain/models/poll/vote-constants';
Expand All @@ -17,7 +17,8 @@ import { UnknownUserLabel } from '../../services/assignment-poll.service';
@Component({
selector: `os-assignment-poll-vote`,
templateUrl: `../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.html`,
styleUrls: [`../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.scss`]
styleUrls: [`../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AssignmentPollVoteComponent extends BasePollVoteComponent<ViewAssignment> {
public unknownUserLabel = UnknownUserLabel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Id } from 'src/app/domain/definitions/key-types';
import { VoteValue } from 'src/app/domain/models/poll/vote-constants';
import {
Expand All @@ -14,7 +14,8 @@ import { ViewOption } from '../../../../../polls';
@Component({
selector: `os-motion-poll-vote`,
templateUrl: `../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.html`,
styleUrls: [`../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.scss`]
styleUrls: [`../../../../../../modules/poll/components/base-poll-vote/base-poll-vote.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MotionPollVoteComponent extends BasePollVoteComponent {
public override readonly settings = {
Expand Down

0 comments on commit 1af1e58

Please sign in to comment.