Merge pull request #1520 from stackernews/edit-ux

Don't hide cancel if edit timer runs out
This commit is contained in:
Keyan 2024-11-01 20:28:43 -05:00 committed by GitHub
commit fd5f649d5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View File

@ -180,7 +180,8 @@ export default function Comment ({
</ActionTooltip>}
</>
}
onEdit={e => { setEdit(!edit) }}
edit={edit}
toggleEdit={e => { setEdit(!edit) }}
editText={edit ? 'cancel' : 'edit'}
/>}

View File

@ -30,7 +30,7 @@ import classNames from 'classnames'
export default function ItemInfo ({
item, full, commentsText = 'comments',
commentTextSingular = 'comment', className, embellishUser, extraInfo, onEdit, editText,
commentTextSingular = 'comment', className, embellishUser, extraInfo, edit, toggleEdit, editText,
onQuoteReply, extraBadges, nested, pinnable, showActionDropdown = true, showUser = true,
setDisableRetry, disableRetry
}) {
@ -151,8 +151,8 @@ export default function ItemInfo ({
showActionDropdown &&
<>
<EditInfo
item={item} canEdit={canEdit}
setCanEdit={setCanEdit} onEdit={onEdit} editText={editText} editThreshold={editThreshold}
item={item} edit={edit} canEdit={canEdit}
setCanEdit={setCanEdit} toggleEdit={toggleEdit} editText={editText} editThreshold={editThreshold}
/>
<PaymentInfo item={item} disableRetry={disableRetry} setDisableRetry={setDisableRetry} />
<ActionDropdown>
@ -311,7 +311,7 @@ function PaymentInfo ({ item, disableRetry, setDisableRetry }) {
)
}
function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold }) {
function EditInfo ({ item, edit, canEdit, setCanEdit, toggleEdit, editText, editThreshold }) {
const router = useRouter()
if (canEdit) {
@ -320,7 +320,7 @@ function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)}
onClick={() => toggleEdit ? toggleEdit() : router.push(`/items/${item.id}/edit`)}
>
<span>{editText || 'edit'} </span>
{(!item.invoice?.actionState || item.invoice?.actionState === 'PAID')
@ -334,5 +334,21 @@ function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold
)
}
if (edit && !canEdit) {
// if we're still editing after timer ran out
return (
<>
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => toggleEdit ? toggleEdit() : router.push(`/items/${item.id}`)}
>
<span>cancel </span>
<span>00:00</span>
</span>
</>
)
}
return null
}