Keep answers when switching market type
This commit is contained in:
parent
8392bb2944
commit
0fc8e2bcc0
|
@ -7,20 +7,19 @@ import { Col } from '../layout/col'
|
|||
import { Row } from '../layout/row'
|
||||
|
||||
export function MultipleChoiceAnswers(props: {
|
||||
answers: string[]
|
||||
setAnswers: (answers: string[]) => void
|
||||
}) {
|
||||
const [answers, setInternalAnswers] = useState(['', '', ''])
|
||||
const { answers, setAnswers } = props
|
||||
|
||||
const setAnswer = (i: number, answer: string) => {
|
||||
const newAnswers = setElement(answers, i, answer)
|
||||
setInternalAnswers(newAnswers)
|
||||
props.setAnswers(newAnswers)
|
||||
setAnswers(newAnswers)
|
||||
}
|
||||
|
||||
const removeAnswer = (i: number) => {
|
||||
const newAnswers = answers.slice(0, i).concat(answers.slice(i + 1))
|
||||
setInternalAnswers(newAnswers)
|
||||
props.setAnswers(newAnswers)
|
||||
setAnswers(newAnswers)
|
||||
}
|
||||
|
||||
const addAnswer = () => setAnswer(answers.length, '')
|
||||
|
|
|
@ -120,7 +120,8 @@ export function NewContract(props: {
|
|||
const [isLogScale, setIsLogScale] = useState<boolean>(!!params?.isLogScale)
|
||||
const [initialValueString, setInitialValueString] = useState(initValue)
|
||||
|
||||
const [answers, setAnswers] = useState<string[]>([]) // for multiple choice
|
||||
// for multiple choice, init to 3 empty answers
|
||||
const [answers, setAnswers] = useState(['', '', ''])
|
||||
|
||||
useEffect(() => {
|
||||
if (groupId)
|
||||
|
@ -285,7 +286,7 @@ export function NewContract(props: {
|
|||
<Spacer h={6} />
|
||||
|
||||
{outcomeType === 'MULTIPLE_CHOICE' && (
|
||||
<MultipleChoiceAnswers setAnswers={setAnswers} />
|
||||
<MultipleChoiceAnswers answers={answers} setAnswers={setAnswers} />
|
||||
)}
|
||||
|
||||
{outcomeType === 'PSEUDO_NUMERIC' && (
|
||||
|
|
Loading…
Reference in New Issue
Block a user