Preview a slimmed-down version of /Create

This commit is contained in:
Austin Chen 2021-12-20 14:46:56 -08:00
parent 3ba96028f4
commit 302c524dcf

View File

@ -8,6 +8,8 @@ import { useUser } from '../hooks/use-user'
import { path } from '../lib/firebase/contracts' import { path } from '../lib/firebase/contracts'
import { createContract } from '../lib/service/create-contract' import { createContract } from '../lib/service/create-contract'
import { Page } from '../components/page' import { Page } from '../components/page'
import { Row } from '../components/layout/row'
import clsx from 'clsx'
// Allow user to create a new contract // Allow user to create a new contract
export default function NewContract() { export default function NewContract() {
@ -21,6 +23,7 @@ export default function NewContract() {
const [question, setQuestion] = useState('') const [question, setQuestion] = useState('')
const [description, setDescription] = useState('') const [description, setDescription] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
const [collapsed, setCollapsed] = useState(true)
async function submit() { async function submit() {
// TODO: add more rigorous error handling for question // TODO: add more rigorous error handling for question
@ -49,52 +52,92 @@ export default function NewContract() {
{/* Create a Tailwind form that takes in all the fields needed for a new contract */} {/* Create a Tailwind form that takes in all the fields needed for a new contract */}
{/* When the form is submitted, create a new contract in the database */} {/* When the form is submitted, create a new contract in the database */}
<form> <form>
<div className="form-control"> <div className="flex justify-between gap-4 items-center">
<label className="label"> <div className="form-control w-full">
<span className="label-text">Question</span> <label className="label">
</label> <span className="label-text">Prediction</span>
</label>
<input <input
type="text" type="text"
placeholder="e.g. Will the FDA approve Paxlovid before Jun 2nd, 2022?" placeholder="e.g. The FDA will approve Paxlovid before Jun 2nd, 2022"
className="input input-bordered" className="input"
value={question} value={question}
onChange={(e) => setQuestion(e.target.value || '')} onChange={(e) => setQuestion(e.target.value || '')}
/> />
</div>
<div className="form-control">
<label className="label">
<span className="label-text">Chance</span>
</label>
<label className="input-group input-group-md w-fit">
<input
type="number"
value={initialProb}
className="input input-bordered input-md"
min={1}
max={99}
onChange={(e) => setInitialProb(parseInt(e.target.value))}
/>
<span>%</span>
</label>
</div>
</div> </div>
<Spacer h={4} /> <div className="mt-2 mb-4">
<a
<div className="form-control"> href="#"
<label className="label"> className="text-sm text-gray-400"
<span className="label-text">Description (optional)</span> onClick={() => setCollapsed(!collapsed)}
</label> >
Advanced
<textarea </a>
className="textarea h-24 textarea-bordered"
placeholder={descriptionPlaceholder}
value={description}
onChange={(e) => setDescription(e.target.value || '')}
></textarea>
</div> </div>
<Spacer h={4} /> {/* Collapsible "Advanced" section */}
<div
tabIndex={0}
className={clsx(
'cursor-pointer relative',
collapsed ? 'collapse-close' : 'collapse-open'
)}
onClick={() => setCollapsed((collapsed) => !collapsed)}
>
<Row>
<div
className="collapse-title p-0 absolute w-0 h-0 min-h-0"
style={{ top: -10, right: 4 }}
/>
</Row>
<div className="collapse-content !p-0 m-0 !bg-transparent">
<div className="form-control">
<label className="label">
<span className="label-text">Description</span>
</label>
<textarea
className="textarea w-full h-24 textarea-bordered"
placeholder={descriptionPlaceholder}
value={description}
onClick={(e) => e.stopPropagation()}
onChange={(e) => setDescription(e.target.value || '')}
></textarea>
</div>
<div className="form-control"> <div className="form-control">
<label className="label"> <label className="label">
<span className="label-text"> <span className="label-text">Resolution date</span>
Initial probability: {initialProb}% </label>
</span> <input
</label> type="date"
className="input"
<input onClick={(e) => e.stopPropagation()}
type="range" value="2012-07-22"
className="range range-lg range-primary" min="2022-01-01"
min="1" max="2022-12-31"
max={99} />
value={initialProb} </div>
onChange={(e) => setInitialProb(parseInt(e.target.value))} </div>
/>
</div> </div>
<Spacer h={4} /> <Spacer h={4} />