From 91e51f828ddc6bd5976e0a8b9b64c2c9adf431ac Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sat, 24 Jun 2023 11:44:36 +0200 Subject: [PATCH] limit parentCid logic to first ReplyModal opening --- src/components/views/All.jsx | 43 +++++++++++++++++-------- src/components/views/Board.jsx | 41 +++++++++++++++++------- src/components/views/Subscriptions.jsx | 41 +++++++++++++++++------- src/components/views/Thread.jsx | 44 +++++++++++++++++--------- src/hooks/stores/useGeneralStore.js | 3 ++ 5 files changed, 120 insertions(+), 52 deletions(-) diff --git a/src/components/views/All.jsx b/src/components/views/All.jsx index f923ac5a..11e60533 100755 --- a/src/components/views/All.jsx +++ b/src/components/views/All.jsx @@ -55,6 +55,7 @@ const All = () => { setIsAuthorEdit, setIsCaptchaOpen, isModerationOpen, setIsModerationOpen, + setReplyQuoteCid, setResolveCaptchaPromise, setSelectedAddress, setSelectedParentCid, @@ -702,11 +703,15 @@ const All = () => { onClick={(e) => { if (e.button === 2) return; e.preventDefault(); - setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); + setSelectedThreadCid(thread.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid}  p/ @@ -983,10 +988,14 @@ const All = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( @@ -1513,10 +1522,14 @@ const All = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid} @@ -1686,10 +1699,14 @@ const All = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index d97e5568..ea9947f9 100755 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -57,6 +57,7 @@ const Board = () => { setModeratingCommentCid, setPendingComment, setPendingCommentIndex, + setReplyQuoteCid, setResolveCaptchaPromise, selectedAddress, setSelectedAddress, setSelectedParentCid, @@ -1148,9 +1149,13 @@ const Board = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid}   {thread.pinned ? ( @@ -1426,9 +1431,13 @@ const Board = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( @@ -1927,9 +1936,13 @@ const Board = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid} @@ -2078,9 +2091,13 @@ const Board = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx index ae7b5a0c..3b4102ef 100755 --- a/src/components/views/Subscriptions.jsx +++ b/src/components/views/Subscriptions.jsx @@ -55,6 +55,7 @@ const Subscriptions = () => { setIsAuthorEdit, setIsCaptchaOpen, isModerationOpen, setIsModerationOpen, + setReplyQuoteCid, setResolveCaptchaPromise, setSelectedAddress, setSelectedParentCid, @@ -711,10 +712,14 @@ const Subscriptions = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid}  p/ @@ -991,10 +996,14 @@ const Subscriptions = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( @@ -1521,10 +1530,14 @@ const Subscriptions = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(thread.shortCid); - setSelectedParentCid(thread.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(thread.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(thread.shortCid); + setSelectedParentCid(thread.cid); + } }} title="Reply to this post">{thread.shortCid} @@ -1694,10 +1707,14 @@ const Subscriptions = () => { if (e.button === 2) return; e.preventDefault(); setSelectedThreadCid(thread.cid); - setIsReplyOpen(true); - setSelectedShortCid(reply.shortCid); - setSelectedParentCid(reply.cid); setSelectedAddress(thread.subplebbitAddress); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid) + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index faa41c31..cb142c53 100755 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -54,6 +54,7 @@ const Thread = () => { isModerationOpen, setIsModerationOpen, isSettingsOpen, setIsSettingsOpen, setModeratingCommentCid, + setReplyQuoteCid, setResolveCaptchaPromise, setPendingComment, setPendingCommentIndex, @@ -842,10 +843,13 @@ const Thread = () => { c/ {}} id="reply-button" style={{ cursor: 'pointer' }} onClick={() => { - setIsReplyOpen(true); - setSelectedParentCid(comment.cid); - setSelectedShortCid(comment.shortCid); - }} title="Reply to this post">{comment.shortCid} + if (isReplyOpen) { + setReplyQuoteCid(comment.shortCid); + } else { + setIsReplyOpen(true); + setSelectedShortCid(comment.shortCid); + setSelectedParentCid(comment.cid); + }}} title="Reply to this post">{comment.shortCid}   {comment.pinned ? ( <> @@ -1079,9 +1083,13 @@ const Thread = () => { {reply.shortCid ? ( { - setIsReplyOpen(true); - setSelectedParentCid(reply.cid); - setSelectedShortCid(reply.shortCid); + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid); + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + } }} title="Reply to this post">{reply.shortCid} ) : ( @@ -1452,10 +1460,13 @@ const Thread = () => { c/ {}} id="reply-button" key={`mob-no2-${comment.cid}`} title="Reply to this post" onClick={() => { - setIsReplyOpen(true); - setSelectedParentCid(comment.cid); - setSelectedShortCid(comment.shortCid); - }}>{comment.shortCid} + if (isReplyOpen) { + setReplyQuoteCid(comment.shortCid); + } else { + setIsReplyOpen(true); + setSelectedShortCid(comment.shortCid); + setSelectedParentCid(comment.cid); + }}}>{comment.shortCid} {commentMediaInfo?.url ? ( @@ -1573,10 +1584,13 @@ const Thread = () => { {reply.shortCid ? ( { - setIsReplyOpen(true); - setSelectedParentCid(reply.cid); - setSelectedShortCid(reply.shortCid); - }} title="Reply to this post">{reply.shortCid} + if (isReplyOpen) { + setReplyQuoteCid(reply.shortCid); + } else { + setIsReplyOpen(true); + setSelectedShortCid(reply.shortCid); + setSelectedParentCid(reply.cid); + }}} title="Reply to this post">{reply.shortCid} ) : ( )} diff --git a/src/hooks/stores/useGeneralStore.js b/src/hooks/stores/useGeneralStore.js index 100f092d..cb66e3fc 100644 --- a/src/hooks/stores/useGeneralStore.js +++ b/src/hooks/stores/useGeneralStore.js @@ -53,6 +53,9 @@ const useGeneralStore = create((set) => ({ publishedComment: '', setPublishedComment: (comment) => set({ publishedComment: comment }), + replyQuoteCid: '', + setReplyQuoteCid: (cid) => set({ replyQuoteCid: cid }), + resolveCaptchaPromise: null, setResolveCaptchaPromise: (resolve) => set({ resolveCaptchaPromise: resolve }),