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'
|
import { Row } from '../layout/row'
|
||||||
|
|
||||||
export function MultipleChoiceAnswers(props: {
|
export function MultipleChoiceAnswers(props: {
|
||||||
|
answers: string[]
|
||||||
setAnswers: (answers: string[]) => void
|
setAnswers: (answers: string[]) => void
|
||||||
}) {
|
}) {
|
||||||
const [answers, setInternalAnswers] = useState(['', '', ''])
|
const { answers, setAnswers } = props
|
||||||
|
|
||||||
const setAnswer = (i: number, answer: string) => {
|
const setAnswer = (i: number, answer: string) => {
|
||||||
const newAnswers = setElement(answers, i, answer)
|
const newAnswers = setElement(answers, i, answer)
|
||||||
setInternalAnswers(newAnswers)
|
setAnswers(newAnswers)
|
||||||
props.setAnswers(newAnswers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeAnswer = (i: number) => {
|
const removeAnswer = (i: number) => {
|
||||||
const newAnswers = answers.slice(0, i).concat(answers.slice(i + 1))
|
const newAnswers = answers.slice(0, i).concat(answers.slice(i + 1))
|
||||||
setInternalAnswers(newAnswers)
|
setAnswers(newAnswers)
|
||||||
props.setAnswers(newAnswers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addAnswer = () => setAnswer(answers.length, '')
|
const addAnswer = () => setAnswer(answers.length, '')
|
||||||
|
|
|
@ -120,7 +120,8 @@ export function NewContract(props: {
|
||||||
const [isLogScale, setIsLogScale] = useState<boolean>(!!params?.isLogScale)
|
const [isLogScale, setIsLogScale] = useState<boolean>(!!params?.isLogScale)
|
||||||
const [initialValueString, setInitialValueString] = useState(initValue)
|
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(() => {
|
useEffect(() => {
|
||||||
if (groupId)
|
if (groupId)
|
||||||
|
@ -285,7 +286,7 @@ export function NewContract(props: {
|
||||||
<Spacer h={6} />
|
<Spacer h={6} />
|
||||||
|
|
||||||
{outcomeType === 'MULTIPLE_CHOICE' && (
|
{outcomeType === 'MULTIPLE_CHOICE' && (
|
||||||
<MultipleChoiceAnswers setAnswers={setAnswers} />
|
<MultipleChoiceAnswers answers={answers} setAnswers={setAnswers} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{outcomeType === 'PSEUDO_NUMERIC' && (
|
{outcomeType === 'PSEUDO_NUMERIC' && (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user