New edit interface for auto resolution
This commit is contained in:
parent
6cf574f33c
commit
1c91cc984a
|
@ -1,4 +1,4 @@
|
|||
import { DotsHorizontalIcon, PencilIcon } from '@heroicons/react/outline'
|
||||
import { DotsHorizontalIcon, PencilIcon, CheckIcon } from '@heroicons/react/outline'
|
||||
import clsx from 'clsx'
|
||||
import dayjs from 'dayjs'
|
||||
import { uniqBy } from 'lodash'
|
||||
|
@ -83,23 +83,16 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC
|
|||
|
||||
{autoResolutionTime && autoResolution && (
|
||||
<>
|
||||
<EditableTime
|
||||
title ='Market autoresolves'
|
||||
time={autoResolutionTime}
|
||||
contract={contract}
|
||||
isCreator={isCreator}
|
||||
dateType='autoResolutionTime'
|
||||
/>
|
||||
<tr>
|
||||
<td>Automatic resolution</td>
|
||||
<EditableTime
|
||||
time={autoResolutionTime}
|
||||
contract={contract}
|
||||
isCreator={isCreator}
|
||||
dateType='autoResolutionTime'
|
||||
/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Default resolution</td>
|
||||
<EditableString
|
||||
value={autoResolution}
|
||||
contract={contract}
|
||||
isCreator={isCreator}
|
||||
dateType='autoResolution'
|
||||
/>
|
||||
<td>Auto resolution</td>
|
||||
<td>{contract.autoResolution}</td>
|
||||
</tr>
|
||||
</>
|
||||
)}
|
||||
|
@ -173,12 +166,13 @@ const getTweetText = (contract: Contract, isCreator: boolean) => {
|
|||
}
|
||||
|
||||
export function EditableTime(props: {
|
||||
title: string
|
||||
time: number
|
||||
contract: Contract
|
||||
isCreator: boolean
|
||||
dateType: contractField
|
||||
}) {
|
||||
const { time, contract, isCreator, dateType } = props
|
||||
const { title, time, contract, isCreator, dateType } = props
|
||||
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const [timeString, setTimeString] = useState(time && formatTime(time))
|
||||
|
@ -194,83 +188,37 @@ export function EditableTime(props: {
|
|||
}
|
||||
|
||||
return (
|
||||
<td>
|
||||
{isEditing ? (
|
||||
<div className="form-control mr-1 items-start">
|
||||
<input
|
||||
type="datetime-local"
|
||||
className="input input-xs"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => setTimeString(e.target.value || '')}
|
||||
min={contract.closeTime}
|
||||
value={timeString}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="form-control mr-1 items-start">{timeString}</div>
|
||||
)}
|
||||
{isCreator &&
|
||||
(isEditing ? (
|
||||
<button className="btn btn-xs btn-ghost" onClick={onSave}>
|
||||
Done
|
||||
</button>
|
||||
) : (
|
||||
<button className="btn btn-xs btn-ghost"
|
||||
onClick={() => setIsEditing(true)}
|
||||
>
|
||||
<PencilIcon className="mr-2 inline h-4 w-4" /> Edit
|
||||
</button>
|
||||
<tr>
|
||||
<td>
|
||||
{title}
|
||||
{isCreator && (
|
||||
isEditing ? (
|
||||
<button className="btn btn-xs btn-ghost" onClick={onSave}>
|
||||
<CheckIcon className="inline h-4 w-4" />
|
||||
</button>
|
||||
):(
|
||||
<button className="btn btn-xs btn-ghost"
|
||||
onClick={() => setIsEditing(true)} >
|
||||
<PencilIcon className="inline h-4 w-4" />
|
||||
</button>
|
||||
))}
|
||||
</td>
|
||||
)
|
||||
}
|
||||
|
||||
export function EditableString(props: {
|
||||
value: string
|
||||
contract: Contract
|
||||
isCreator: boolean
|
||||
dateType: contractField
|
||||
}) {
|
||||
const { value, contract, isCreator, dateType } = props
|
||||
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const [newValue, setTimeString] = useState(value)
|
||||
const onSave = () => {
|
||||
if (newValue === value) setIsEditing(false)
|
||||
else {
|
||||
updateContract(contract.id, {
|
||||
[dateType]: newValue
|
||||
})
|
||||
setIsEditing(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<td>
|
||||
{isEditing ? (
|
||||
<input
|
||||
style={{ maxWidth: 50 }}
|
||||
className="input input-xs resize-none"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => setTimeString(e.target.value || '')}
|
||||
min={contract.closeTime}
|
||||
value={newValue}
|
||||
/>
|
||||
) : (
|
||||
<>{newValue}</>
|
||||
)}
|
||||
{isCreator &&
|
||||
(isEditing ? (
|
||||
<button className="btn btn-xs btn-ghost" onClick={onSave}>
|
||||
Done
|
||||
</button>
|
||||
) : (
|
||||
<button className="btn btn-xs btn-ghost"
|
||||
onClick={() => setIsEditing(true)}
|
||||
>
|
||||
<PencilIcon className="mr-2 inline h-4 w-4" /> Edit
|
||||
</button>
|
||||
))}
|
||||
</td>
|
||||
</td>
|
||||
<td>
|
||||
{isEditing ? (
|
||||
<div className="form-control mr-1 items-start">
|
||||
<input
|
||||
type="datetime-local"
|
||||
className="input input-xs"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onChange={(e) => setTimeString(e.target.value || '')}
|
||||
min={contract.closeTime}
|
||||
value={timeString}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="form-control mr-1 items-start">{timeString}</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ export function Modal(props: {
|
|||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<div className="inline-block transform overflow-hidden text-left align-bottom transition-all sm:my-8 sm:w-full sm:max-w-md sm:p-6 sm:align-middle">
|
||||
<div className="inline-block transform overflow-hidden text-left align-bottom transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 sm:align-middle">
|
||||
{children}
|
||||
</div>
|
||||
</Transition.Child>
|
||||
|
|
Loading…
Reference in New Issue
Block a user