From 47aa173e5e26391b9df6eb8593fa8fee7d326705 Mon Sep 17 00:00:00 2001 From: plebbitor Date: Tue, 11 Apr 2023 17:17:32 +0200 Subject: [PATCH] fix onChallenge assertion error --- src/components/views/Board.jsx | 49 +++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 53571d96..633a8e04 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -122,20 +122,6 @@ const Board = () => { } - const publishCommentOptions = { - displayName: nameRef.current ? nameRef.current.value : undefined, - title: subjectRef.current ? subjectRef.current.value : undefined, - content: commentRef.current ? commentRef.current.value : undefined, - link: linkRef.current ? linkRef.current.value : undefined, - subplebbitAddress: selectedAddress, - onChallenge, - onChallengeVerification, - onError: (error) => { - setErrorMessage(error); - } - }; - - const resetFields = () => { nameRef.current.value = ''; subjectRef.current.value = ''; @@ -143,6 +129,39 @@ const Board = () => { linkRef.current.value = ''; }; + + const [publishCommentOptions, setPublishCommentOptions] = useState({ + subplebbitAddress: selectedAddress, + onChallenge, + onChallengeVerification, + onError: (error) => { + setErrorMessage(error); + }, + }); + + + const handleSubmit = async (event) => { + event.preventDefault(); + + setPublishCommentOptions((prevPublishCommentOptions) => ({ + ...prevPublishCommentOptions, + displayName: nameRef.current.value || undefined, + title: subjectRef.current.value || undefined, + content: commentRef.current.value || undefined, + link: linkRef.current.value || undefined, + })); + }; + + + useEffect(() => { + if (publishCommentOptions.content) { + (async () => { + await publishComment(); + resetFields(); + })(); + } + }, [publishCommentOptions]); + const { publishComment } = usePublishComment(publishCommentOptions); @@ -295,7 +314,7 @@ const Board = () => { {await publishComment(); resetFields();}} /> + onClick={handleSubmit} />