From 3538b9b6414208943c17e77d074474e5dee671a7 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 23 Jun 2023 12:48:42 +0200 Subject: [PATCH] Update Thread.jsx --- src/components/views/Thread.jsx | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index ce74a1e3..2cc2cfb4 100755 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -1661,7 +1661,55 @@ const Thread = () => { }}> {`c/${shortParentCid}`}{shortParentCid === comment.shortCid ? " (OP)" : null} - + { + postRefs.current[quoteShortParentCid] = ref; + }} + postQuoteOnClick={(quoteShortParentCid) => { + handleQuoteClick(reply, quoteShortParentCid, null) + }} + postQuoteOnOver={(quoteShortParentCid) => { + const quoteParentCid = cidTracker[quoteShortParentCid]; + if (outOfViewCid !== quoteParentCid) { + handleQuoteHover(reply, quoteShortParentCid, () => { + setOutOfViewCid(quoteParentCid); + + const rect = postRefs.current[quoteShortParentCid].getBoundingClientRect(); + const distanceToRight = window.innerWidth - rect.right; + const distanceToTop = rect.top; + const distanceToBottom = window.innerHeight - rect.bottom; + let top; + + if (distanceToTop < postOnHoverHeight / 2) { + top = window.scrollY - 5; + } else if (distanceToBottom < postOnHoverHeight / 2) { + top = window.scrollY - postOnHoverHeight + window.innerHeight - 10; + } else { + top = rect.top + window.scrollY - postOnHoverHeight / 2; + } + + if (distanceToRight < 200) { + setOutOfViewPosition({ + top, + right: window.innerWidth - rect.left - 10, + maxWidth: rect.left - 5 + }); + } else { + setOutOfViewPosition({ + top, + left: rect.left + rect.width + 5, + maxWidth: window.innerWidth - rect.left - rect.width - 5 + }); + } + }) + }} + } + postQuoteOnLeave={() => { + removeHighlight(); + setOutOfViewCid(null); + }} + />