From 3d2d510259b0e7ac4bcfecdff872d928a550709c Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Thu, 29 Aug 2024 17:48:34 +0200 Subject: [PATCH] fix(post form): user could post empty comment using spaces --- src/components/post-form/post-form.tsx | 14 +++++++++----- src/components/reply-modal/reply-modal.tsx | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/post-form/post-form.tsx b/src/components/post-form/post-form.tsx index ad27de6f..321a54f2 100644 --- a/src/components/post-form/post-form.tsx +++ b/src/components/post-form/post-form.tsx @@ -180,8 +180,12 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid: } }, [anonMode, getNewSigner, account, setSubmitStore, displayName]); - const onPublishPost = async () => { - if (!title && !content && !link) { + const onPublishPost = () => { + const currentTitle = subjectRef.current?.value.trim() || ''; + const currentContent = textRef.current?.value.trim() || ''; + const currentUrl = urlRef.current?.value.trim() || ''; + + if (!currentTitle && !currentContent && !currentUrl) { alert(`Cannot post empty comment`); return; } @@ -248,10 +252,10 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid: }; const onPublishReply = () => { - const currentContent = textRef.current?.value || ''; - const currentUrl = urlRef.current?.value || ''; + const currentContent = textRef.current?.value.trim() || ''; + const currentUrl = urlRef.current?.value.trim() || ''; - if (!currentContent.trim() && !currentUrl) { + if (!currentContent && !currentUrl) { alert(`Cannot post empty comment`); return; } diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index bac1bc9e..1bae61b3 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -66,10 +66,10 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s }, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName]); const onPublishReply = () => { - const currentContent = textRef.current?.value || ''; - const currentUrl = urlRef.current?.value || ''; + const currentContent = textRef.current?.value.slice(contentPrefix.length).trim() || ''; + const currentUrl = urlRef.current?.value.trim() || ''; - if (!currentContent.trim() && !currentUrl) { + if (!currentContent && !currentUrl) { alert(`Cannot post empty comment`); return; }