diff --git a/src/components/post/reply-quote-preview/reply-quote-preview.tsx b/src/components/post/reply-quote-preview/reply-quote-preview.tsx index 990c0f90..c01fa8b0 100644 --- a/src/components/post/reply-quote-preview/reply-quote-preview.tsx +++ b/src/components/post/reply-quote-preview/reply-quote-preview.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; import { Link } from 'react-router-dom'; import { Comment } from '@plebbit/plebbit-react-hooks'; @@ -104,12 +104,10 @@ const DesktopQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, i const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, isQuotelinkReply }: ReplyQuotePreviewProps) => { const [hoveredCid, setHoveredCid] = useState(null); - const placementRef = useRef('bottom'); - const quotelinkRef = useRef(null); const { refs, floatingStyles, update } = useFloating({ - placement: placementRef.current, - middleware: [shift({ padding: 10 })], + placement: 'bottom', + middleware: [shift({ padding: isBacklinkReply ? 5 : 10 })], whileElementsMounted: autoUpdate, }); @@ -120,25 +118,9 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is }; }, [update]); - const handleClickOutside = useCallback( - (event: MouseEvent) => { - if (quotelinkRef.current && !quotelinkRef.current.contains(event.target as Node)) { - setHoveredCid(null); - } - }, - [quotelinkRef, setHoveredCid], - ); - - useEffect(() => { - document.addEventListener('mousedown', handleClickOutside); - return () => { - document.removeEventListener('mousedown', handleClickOutside); - }; - }, [handleClickOutside]); - const replyBacklink = ( - - setHoveredCid(backlinkReply?.cid)}> + <> + setHoveredCid(backlinkReply?.cid)} onMouseLeave={() => setHoveredCid(null)}> c/{backlinkReply?.shortCid}{' '} @@ -151,13 +133,13 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is , document.body, )} - + ); const replyQuotelink = ( - - setHoveredCid(quotelinkReply?.cid)}> - {quotelinkReply?.shortCid}{' '} + <> + setHoveredCid(quotelinkReply?.cid)} onMouseLeave={() => setHoveredCid(null)}> + c/{quotelinkReply?.shortCid}{' '} # @@ -170,7 +152,7 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is , document.body, )} - + ); return isBacklinkReply ? replyBacklink : isQuotelinkReply && replyQuotelink;