From 9597b1ae4138712c583b1060a2406c05083b6651 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Wed, 31 Jan 2024 10:25:22 +0100 Subject: [PATCH] Avoid fetching more emails when first query loading (#3709) Co-authored-by: Thomas Trompette --- .../emails/components/EmailThreads.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx b/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx index 816b63219..879bda969 100644 --- a/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx +++ b/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx @@ -75,12 +75,21 @@ export const EmailThreads = ({ pageSize: TIMELINE_THREADS_DEFAULT_PAGE_SIZE, } as GetTimelineThreadsFromPersonIdQueryVariables; - const { data, loading, fetchMore, error } = useQuery(threadQuery, { + const { + data, + loading: firstQueryLoading, + fetchMore, + error, + } = useQuery(threadQuery, { variables: threadQueryVariables, }); const fetchMoreRecords = async () => { - if (emailThreadsPage.hasNextPage && !isFetchingMoreEmails) { + if ( + emailThreadsPage.hasNextPage && + !isFetchingMoreEmails && + !firstQueryLoading + ) { setIsFetchingMoreEmails(true); await fetchMore({ @@ -144,7 +153,7 @@ export const EmailThreads = ({ } fontColor={H1TitleFontColor.Primary} /> - {!loading && ( + {!firstQueryLoading && ( {timelineThreads?.map((thread: TimelineThread, index: number) => ( )}