Improve create page UI (#746)

* Adjust create page styles

* Keep answers when switching market type
This commit is contained in:
Sinclair Chen 2022-08-11 14:41:21 -07:00 committed by GitHub
parent dc95587cca
commit daba28423a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 14 deletions

View File

@ -1,26 +1,23 @@
import { MAX_ANSWER_LENGTH } from 'common/answer' import { MAX_ANSWER_LENGTH } from 'common/answer'
import { useState } from 'react'
import Textarea from 'react-expanding-textarea' import Textarea from 'react-expanding-textarea'
import { XIcon } from '@heroicons/react/solid' import { XIcon } from '@heroicons/react/solid'
import { Col } from '../layout/col' 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, '')
@ -40,10 +37,10 @@ export function MultipleChoiceAnswers(props: {
/> />
{answers.length > 2 && ( {answers.length > 2 && (
<button <button
className="btn btn-xs btn-outline ml-2" className="-mr-2 rounded p-2"
onClick={() => removeAnswer(i)} onClick={() => removeAnswer(i)}
> >
<XIcon className="h-4 w-4 flex-shrink-0" /> <XIcon className="h-5 w-5 flex-shrink-0" />
</button> </button>
)} )}
</Row> </Row>

View File

@ -22,7 +22,10 @@ export function ChoicesToggleGroup(props: {
} = props } = props
return ( return (
<RadioGroup <RadioGroup
className={clsx(className, 'flex flex-row flex-wrap items-center gap-3')} className={clsx(
className,
'flex flex-row flex-wrap items-center gap-2 sm:gap-3'
)}
value={currentChoice.toString()} value={currentChoice.toString()}
onChange={setChoice} onChange={setChoice}
> >

View File

@ -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' && (
@ -299,7 +300,7 @@ export function NewContract(props: {
<Row className="gap-2"> <Row className="gap-2">
<input <input
type="number" type="number"
className="input input-bordered" className="input input-bordered w-32"
placeholder="MIN" placeholder="MIN"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
onChange={(e) => setMinString(e.target.value)} onChange={(e) => setMinString(e.target.value)}
@ -310,7 +311,7 @@ export function NewContract(props: {
/> />
<input <input
type="number" type="number"
className="input input-bordered" className="input input-bordered w-32"
placeholder="MAX" placeholder="MAX"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
onChange={(e) => setMaxString(e.target.value)} onChange={(e) => setMaxString(e.target.value)}