Fix issue with enter not properly submitting the edit info modal

This commit is contained in:
Jackson Harper
2023-06-13 15:41:28 +08:00
parent 517e82462e
commit ae4af84f5f
3 changed files with 23 additions and 29 deletions

View File

@ -47,6 +47,10 @@ type RecommendationCommentsProps = {
recommendationsWithNotes: Recommendation[]
}
export interface UpdateTitleEvent extends Event {
title?: string
}
const RecommendationComments = (
props: RecommendationCommentsProps
): JSX.Element => {
@ -251,10 +255,6 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element {
setLabels(event.labels ?? [])
}
interface UpdateTitleEvent extends Event {
title?: string
}
const handleUpdateTitle = (event: UpdateTitleEvent) => {
if (event.title) {
setTitle(event.title)

View File

@ -1,4 +1,5 @@
import {
ModalButtonBar,
ModalContent,
ModalOverlay,
ModalRoot,
@ -215,7 +216,15 @@ function EditItemModal(props: EditItemModalProps): JSX.Element {
}
return (
<ModalRoot defaultOpen onOpenChange={props.onOpenChange} css={{}}>
<ModalRoot
defaultOpen
modal={true}
onOpenChange={() => {
console.log('props.onOpenChange')
props.onOpenChange(false)
}}
css={{}}
>
<ModalOverlay />
<ModalContent
css={{ bg: '$grayBg', p: '20px', maxWidth: '420px' }}
@ -230,6 +239,7 @@ function EditItemModal(props: EditItemModalProps): JSX.Element {
<form
onSubmit={(event) => {
event.preventDefault()
props.onSave(title, author, description, savedAt, publishedAt)
}}
>
<HStack distribution="start" css={{ width: '100%' }}>
@ -309,30 +319,10 @@ function EditItemModal(props: EditItemModalProps): JSX.Element {
}}
maxLength={4000}
/>
<HStack distribution="end" css={{ mt: '12px', width: '100%' }}>
<Button
onClick={() => props.onOpenChange(false)}
style="cancelGeneric"
css={{ mr: '5px' }}
>
Cancel
</Button>
<Button
onClick={() => {
props.onSave(
title,
author,
description,
savedAt,
publishedAt
)
}}
style="ctaDarkYellow"
css={{ mb: '0px' }}
>
Save Changes
</Button>
</HStack>
<ModalButtonBar
onOpenChange={props.onOpenChange}
acceptButtonLabel="Save Changes"
/>
</form>
</Box>
</VStack>

View File

@ -536,6 +536,10 @@ export default function Home(): JSX.Element {
article.description = description
article.savedAt = savedAt
article.publishedAt = publishedAt
const titleEvent = new Event('updateTitle') as UpdateTitleEvent
titleEvent.title = title
document.dispatchEvent(titleEvent)
}}
/>
)}