Desktop poll code clean up and refinements (#120)

This commit is contained in:
Luke Vella 2022-04-21 13:01:29 +01:00 committed by GitHub
parent 8cd1db41db
commit 00b72d01bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 160 additions and 146 deletions

View file

@ -18,6 +18,7 @@ type PollContextValue = {
targetTimeZone: string;
setTargetTimeZone: (timeZone: string) => void;
pollType: "date" | "timeSlot";
highScore: number;
getParticipantsWhoVotedForOption: (optionId: string) => Participant[]; // maybe just attach votes to parsed options
getParticipantById: (
participantId: string,
@ -60,6 +61,13 @@ export const PollContextProvider: React.VoidFunctionComponent<{
}, [participantById, poll.options]);
const contextValue = React.useMemo<PollContextValue>(() => {
let highScore = 1;
poll.options.forEach((option) => {
if (option.votes.length > highScore) {
highScore = option.votes.length;
}
});
const parsedOptions = decodeOptions(
poll.options,
poll.timeZone,
@ -84,6 +92,7 @@ export const PollContextProvider: React.VoidFunctionComponent<{
getParticipantById: (participantId) => {
return participantById[participantId];
},
highScore,
getParticipantsWhoVotedForOption: (optionId: string) =>
participantsByOptionId[optionId],
getVote: (participantId, optionId) => {