From 4cd61db1ea1864651a6334438c32023af0fbe090 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 8 Jun 2021 21:13:56 -0700 Subject: [PATCH] fix: Move views loading to avoid duplicate request --- app/components/DocumentMetaWithViews.js | 6 ++++++ app/components/DocumentViews.js | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/components/DocumentMetaWithViews.js b/app/components/DocumentMetaWithViews.js index 92b653f2a..cd0b79764 100644 --- a/app/components/DocumentMetaWithViews.js +++ b/app/components/DocumentMetaWithViews.js @@ -23,6 +23,12 @@ function DocumentMetaWithViews({ to, isDraft, document, ...rest }: Props) { const totalViewers = documentViews.length; const onlyYou = totalViewers === 1 && documentViews[0].user.id; + React.useEffect(() => { + if (!document.isDeleted) { + views.fetchPage({ documentId: document.id }); + } + }, [views, document.id, document.isDeleted]); + const popover = usePopoverState({ gutter: 8, placement: "bottom", diff --git a/app/components/DocumentViews.js b/app/components/DocumentViews.js index 180cb75f2..143524647 100644 --- a/app/components/DocumentViews.js +++ b/app/components/DocumentViews.js @@ -19,12 +19,6 @@ function DocumentViews({ document, isOpen }: Props) { const { t } = useTranslation(); const { views, presence } = useStores(); - React.useEffect(() => { - if (!document.isDeleted) { - views.fetchPage({ documentId: document.id }); - } - }, [views, document.id, document.isDeleted]); - let documentPresence = presence.get(document.id); documentPresence = documentPresence ? Array.from(documentPresence.values())