FIX: Show every voter only once. (#6746)
Each voter is represented by an object and Set does not properly check for equality.
This commit is contained in:
parent
2ee2e5c981
commit
285ff3bfbd
|
@ -117,7 +117,14 @@ createWidget("discourse-poll-voters", {
|
||||||
attrs.pollType === "number"
|
attrs.pollType === "number"
|
||||||
? result.voters
|
? result.voters
|
||||||
: result.voters[attrs.optionId];
|
: result.voters[attrs.optionId];
|
||||||
state.voters = [...new Set([...state.voters, ...newVoters])];
|
|
||||||
|
const existingVoters = new Set(state.voters.map(voter => voter.username));
|
||||||
|
newVoters.forEach(voter => {
|
||||||
|
if (!existingVoters.has(voter.username)) {
|
||||||
|
existingVoters.add(voter.username);
|
||||||
|
state.voters.push(voter);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.scheduleRerender();
|
this.scheduleRerender();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1344,7 +1344,7 @@ test("Public poll", async assert => {
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".poll-voters:first li").length,
|
find(".poll-voters:first li").length,
|
||||||
50,
|
26,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue