From bbcfaf0fd5a382d177cbc985d2daa480b92d6edf Mon Sep 17 00:00:00 2001 From: David Ernst Date: Tue, 18 Jul 2023 20:23:36 -0700 Subject: [PATCH] /vote submitted: respect type: 'ranked-choice-irv' in Unlocked & Encrypted widgets --- src/vote/RankedChoiceItem.tsx | 4 +++- src/vote/submitted/SubmittedScreen.tsx | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vote/RankedChoiceItem.tsx b/src/vote/RankedChoiceItem.tsx index f1823b51..2b042bf3 100644 --- a/src/vote/RankedChoiceItem.tsx +++ b/src/vote/RankedChoiceItem.tsx @@ -6,13 +6,15 @@ import { Label, TitleDescriptionQuestion } from './Item' import { Item as ItemType } from './storeElectionInfo' import { State } from './vote-state' +export const defaultRankingsAllowed = 3 + export const RankedChoiceItem = ({ description, dispatch, id = 'vote', options, question, - rankings_allowed = 4, + rankings_allowed = defaultRankingsAllowed, state, title, }: ItemType & { diff --git a/src/vote/submitted/SubmittedScreen.tsx b/src/vote/submitted/SubmittedScreen.tsx index a1d18b59..e3af2712 100644 --- a/src/vote/submitted/SubmittedScreen.tsx +++ b/src/vote/submitted/SubmittedScreen.tsx @@ -3,6 +3,7 @@ import { flatten } from 'lodash-es' import Link from 'next/link' import { useEffect } from 'react' +import { defaultRankingsAllowed } from '../RankedChoiceItem' import { State } from '../vote-state' import { DetailedEncryptionReceipt } from './DetailedEncryptionReceipt' import { EncryptedVote } from './EncryptedVote' @@ -21,15 +22,15 @@ export function SubmittedScreen({ // Widen the page for the tables useEffect(() => { const mainEl = document.getElementsByTagName('main')[0] - if (mainEl) { - mainEl.style.maxWidth = '880px' - } + if (mainEl) mainEl.style.maxWidth = '880px' }) const columns = flatten( - state.ballot_design?.map(({ id, multiple_votes_allowed }) => { - return multiple_votes_allowed - ? new Array(multiple_votes_allowed).fill('').map((_, index) => `${id || 'vote'}_${index + 1}`) + state.ballot_design?.map(({ id, multiple_votes_allowed, type }) => { + return multiple_votes_allowed || type === 'ranked-choice-irv' + ? new Array(multiple_votes_allowed || defaultRankingsAllowed) + .fill('') + .map((_, index) => `${id || 'vote'}_${index + 1}`) : id || 'vote' }), )