Skip to content

Commit

Permalink
Set all Score votes to BLANK by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dsernst committed Apr 30, 2024
1 parent 4966cfb commit 08560a3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/vote/ScoreItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { range } from 'lodash-es'
import { Dispatch } from 'react'
import { Dispatch, useEffect } from 'react'
import { default_max_score, default_min_score } from 'src/admin/BallotDesign/Wizard'

import { Label, TitleDescriptionQuestion } from './Item'
Expand All @@ -25,6 +25,21 @@ export const ScoreItem = ({

const scoreOptions = range(min_score, max_score + 1)

// On first load, set all scores to 'BLANK'
useEffect(() => {
const update: Record<string, string> = {}
options.forEach(({ name, value }) => {
const val = value || name
const key = `${id}_${val}`

// Stop if we already have a stored value
if (state.plaintext[key]) return

update[key] = `BLANK`
})
dispatch(update)
}, [])

return (
<>
<TitleDescriptionQuestion {...{ description, question, title }} />
Expand Down

0 comments on commit 08560a3

Please sign in to comment.