From 158aefe13cd49a5cd4aa262a8ec6f68c6983cddc Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Wed, 20 Dec 2023 11:34:06 +0100 Subject: [PATCH] feat(reply form): allow posting replies with a link and no content --- src/components/reply-form/reply-form.tsx | 4 ++-- src/hooks/use-reply.ts | 27 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/components/reply-form/reply-form.tsx b/src/components/reply-form/reply-form.tsx index 6d3d259e..030f561f 100644 --- a/src/components/reply-form/reply-form.tsx +++ b/src/components/reply-form/reply-form.tsx @@ -47,8 +47,8 @@ const ReplyForm = ({ cid, isReplyingToReply, hideReplyForm }: ReplyFormProps) => const currentContent = textRef.current?.value || ''; const currentUrl = urlRef.current?.value || ''; - if (!currentContent.trim()) { - alert(`missing content`); + if (!currentContent.trim() && !currentUrl) { + alert(`missing content or url`); return; } diff --git a/src/hooks/use-reply.ts b/src/hooks/use-reply.ts index 6686de78..322ede73 100644 --- a/src/hooks/use-reply.ts +++ b/src/hooks/use-reply.ts @@ -85,9 +85,30 @@ const useReply = (comment: Comment) => { const setContent = useMemo( () => ({ - content: (newContent: string) => setReplyStore({ subplebbitAddress, parentCid, content: newContent, link: link || undefined, spoiler: spoiler || false }), - link: (newLink: string) => setReplyStore({ subplebbitAddress, parentCid, content: content, link: newLink || undefined, spoiler: spoiler || false }), - spoiler: (newSpoiler: boolean) => setReplyStore({ subplebbitAddress, parentCid, content: content, link: link || undefined, spoiler: newSpoiler }), + content: (newContent: string) => + setReplyStore({ + subplebbitAddress, + parentCid, + content: newContent === '' ? undefined : newContent, + link: link || undefined, + spoiler: spoiler || false, + }), + link: (newLink: string) => + setReplyStore({ + subplebbitAddress, + parentCid, + content: content, + link: newLink || undefined, + spoiler: spoiler || false, + }), + spoiler: (newSpoiler: boolean) => + setReplyStore({ + subplebbitAddress, + parentCid, + content: content, + link: link || undefined, + spoiler: newSpoiler, + }), }), [subplebbitAddress, parentCid, setReplyStore, content, link, spoiler], );