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 clsx from 'clsx'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { uniqBy } from 'lodash'
|
import { uniqBy } from 'lodash'
|
||||||
|
@ -83,23 +83,16 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC
|
||||||
|
|
||||||
{autoResolutionTime && autoResolution && (
|
{autoResolutionTime && autoResolution && (
|
||||||
<>
|
<>
|
||||||
<tr>
|
|
||||||
<td>Automatic resolution</td>
|
|
||||||
<EditableTime
|
<EditableTime
|
||||||
|
title ='Market autoresolves'
|
||||||
time={autoResolutionTime}
|
time={autoResolutionTime}
|
||||||
contract={contract}
|
contract={contract}
|
||||||
isCreator={isCreator}
|
isCreator={isCreator}
|
||||||
dateType='autoResolutionTime'
|
dateType='autoResolutionTime'
|
||||||
/>
|
/>
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Default resolution</td>
|
<td>Auto resolution</td>
|
||||||
<EditableString
|
<td>{contract.autoResolution}</td>
|
||||||
value={autoResolution}
|
|
||||||
contract={contract}
|
|
||||||
isCreator={isCreator}
|
|
||||||
dateType='autoResolution'
|
|
||||||
/>
|
|
||||||
</tr>
|
</tr>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -173,12 +166,13 @@ const getTweetText = (contract: Contract, isCreator: boolean) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EditableTime(props: {
|
export function EditableTime(props: {
|
||||||
|
title: string
|
||||||
time: number
|
time: number
|
||||||
contract: Contract
|
contract: Contract
|
||||||
isCreator: boolean
|
isCreator: boolean
|
||||||
dateType: contractField
|
dateType: contractField
|
||||||
}) {
|
}) {
|
||||||
const { time, contract, isCreator, dateType } = props
|
const { title, time, contract, isCreator, dateType } = props
|
||||||
|
|
||||||
const [isEditing, setIsEditing] = useState(false)
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
const [timeString, setTimeString] = useState(time && formatTime(time))
|
const [timeString, setTimeString] = useState(time && formatTime(time))
|
||||||
|
@ -194,6 +188,21 @@ export function EditableTime(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<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>
|
||||||
<td>
|
<td>
|
||||||
{isEditing ? (
|
{isEditing ? (
|
||||||
<div className="form-control mr-1 items-start">
|
<div className="form-control mr-1 items-start">
|
||||||
|
@ -209,68 +218,7 @@ export function EditableTime(props: {
|
||||||
) : (
|
) : (
|
||||||
<div className="form-control mr-1 items-start">{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>
|
|
||||||
))}
|
|
||||||
</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>
|
||||||
|
</tr>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function Modal(props: {
|
||||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
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}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</Transition.Child>
|
</Transition.Child>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user