From ae4af84f5fd6e5cc46453759b3896eb508e6cc6f Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 13 Jun 2023 15:41:28 +0800 Subject: [PATCH] Fix issue with enter not properly submitting the edit info modal --- .../templates/article/ArticleContainer.tsx | 8 ++-- .../templates/homeFeed/EditItemModals.tsx | 40 +++++++------------ .../web/pages/[username]/[slug]/index.tsx | 4 ++ 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/packages/web/components/templates/article/ArticleContainer.tsx b/packages/web/components/templates/article/ArticleContainer.tsx index abc7ee6ff..3e362fcd7 100644 --- a/packages/web/components/templates/article/ArticleContainer.tsx +++ b/packages/web/components/templates/article/ArticleContainer.tsx @@ -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) diff --git a/packages/web/components/templates/homeFeed/EditItemModals.tsx b/packages/web/components/templates/homeFeed/EditItemModals.tsx index 890c92ca5..a147990e4 100644 --- a/packages/web/components/templates/homeFeed/EditItemModals.tsx +++ b/packages/web/components/templates/homeFeed/EditItemModals.tsx @@ -1,4 +1,5 @@ import { + ModalButtonBar, ModalContent, ModalOverlay, ModalRoot, @@ -215,7 +216,15 @@ function EditItemModal(props: EditItemModalProps): JSX.Element { } return ( - + { + console.log('props.onOpenChange') + props.onOpenChange(false) + }} + css={{}} + > { event.preventDefault() + props.onSave(title, author, description, savedAt, publishedAt) }} > @@ -309,30 +319,10 @@ function EditItemModal(props: EditItemModalProps): JSX.Element { }} maxLength={4000} /> - - - - + diff --git a/packages/web/pages/[username]/[slug]/index.tsx b/packages/web/pages/[username]/[slug]/index.tsx index 63299b2e5..656edafcf 100644 --- a/packages/web/pages/[username]/[slug]/index.tsx +++ b/packages/web/pages/[username]/[slug]/index.tsx @@ -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) }} /> )}