From 359031c1df344a2eea81c571b1fceb60bca453e1 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Mon, 6 May 2024 22:49:23 +0200 Subject: [PATCH] fix(post form): close after publish, reset fields --- src/components/post-form/post-form.tsx | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/post-form/post-form.tsx b/src/components/post-form/post-form.tsx index 2a58b31f..eb384f4a 100644 --- a/src/components/post-form/post-form.tsx +++ b/src/components/post-form/post-form.tsx @@ -58,17 +58,30 @@ const LinkTypePreviewer = ({ link }: { link: string }) => { return isValidURL(link) ? mediaInfo?.type : 'Invalid URL'; }; -const PostFormTable = () => { +const PostFormTable = ({ closeForm }: { closeForm: () => void }) => { const { t } = useTranslation(); const account = useAccount(); const { displayName } = account?.author || {}; - const [url, setUrl] = useState(''); - const { title, content, link, publishCommentOptions, setSubmitStore, resetSubmitStore } = useSubmitStore(); - const { index, publishComment } = usePublishComment(publishCommentOptions); + const textRef = useRef(null); + const urlRef = useRef(null); + const subjectRef = useRef(null); + + const resetFields = () => { + if (textRef.current) { + textRef.current.value = ''; + } + if (urlRef.current) { + urlRef.current.value = ''; + } + if (subjectRef.current) { + subjectRef.current.value = ''; + } + }; + const onPublishPost = () => { if (!title && !content && !link) { alert(`Cannot post empty comment`); @@ -96,6 +109,7 @@ const PostFormTable = () => { useEffect(() => { if (typeof index === 'number') { resetSubmitStore(); + resetFields(); navigate(`/profile/${index}`); } }, [index, resetSubmitStore, navigate]); @@ -106,9 +120,6 @@ const PostFormTable = () => { const cid = params?.commentCid as string; const { setContent, resetContent, replyIndex, publishReply } = useReply({ cid, subplebbitAddress }); - const textRef = useRef(null); - const urlRef = useRef(null); - const onPublishReply = () => { const currentContent = textRef.current?.value || ''; const currentUrl = urlRef.current?.value || ''; @@ -128,6 +139,8 @@ const PostFormTable = () => { useEffect(() => { if (typeof replyIndex === 'number') { resetContent(); + resetFields(); + closeForm(); } }, [replyIndex, resetContent]); @@ -152,6 +165,7 @@ const PostFormTable = () => { { setSubmitStore({ title: e.target.value }); }} @@ -234,7 +248,7 @@ const PostForm = () => { ] ) : ( - + setShowForm(false)} /> )}
@@ -249,7 +263,7 @@ const PostForm = () => { - {showForm && } + {showForm && setShowForm(false)} />} )}