From f3c8b7306bc3ff720accd21445623237ab8da19b Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Fri, 21 Jul 2023 18:59:16 +0530 Subject: [PATCH] fix: cleanup --- app/components/HoverPreview/HoverPreview.tsx | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/components/HoverPreview/HoverPreview.tsx b/app/components/HoverPreview/HoverPreview.tsx index 3f204cb4ab..f4f129f7d0 100644 --- a/app/components/HoverPreview/HoverPreview.tsx +++ b/app/components/HoverPreview/HoverPreview.tsx @@ -32,18 +32,22 @@ function HoverPreviewInternal({ element, onClose }: Props) { const timerOpen = React.useRef>(); const cardRef = React.useRef(null); const stores = useStores(); - const { data, request, loading } = useRequest(() => - client.post("/urls.unfurl", { - url, - documentId: stores.ui.activeDocumentId, - }) + const { data, request, loading } = useRequest( + React.useCallback( + () => + client.post("/urls.unfurl", { + url, + documentId: stores.ui.activeDocumentId, + }), + [url, stores.ui.activeDocumentId] + ) ); React.useEffect(() => { if (url) { void request(); } - }, [url]); + }, [url, request]); const startCloseTimer = React.useCallback(() => { stopOpenTimer(); @@ -101,15 +105,15 @@ function HoverPreviewInternal({ element, onClose }: Props) { }; }, [element, startCloseTimer, data, loading]); - const anchorBounds = element.getBoundingClientRect(); + const elemBounds = element.getBoundingClientRect(); const cardBounds = cardRef.current?.getBoundingClientRect(); const left = cardBounds ? Math.min( - anchorBounds.left, + elemBounds.left, window.innerWidth - CARD_PADDING - CARD_MAX_WIDTH ) - : anchorBounds.left; - const leftOffset = anchorBounds.left - left; + : elemBounds.left; + const leftOffset = elemBounds.left - left; if (loading) { return ; @@ -122,7 +126,7 @@ function HoverPreviewInternal({ element, onClose }: Props) { return ( @@ -150,7 +154,7 @@ function HoverPreviewInternal({ element, onClose }: Props) { ) : null} - + ) : null}