Avoid fetching more emails when first query loading (#3709)

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thomas Trompette 2024-01-31 10:25:22 +01:00 committed by GitHub
parent 06e35e5119
commit 9597b1ae41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -75,12 +75,21 @@ export const EmailThreads = ({
pageSize: TIMELINE_THREADS_DEFAULT_PAGE_SIZE, pageSize: TIMELINE_THREADS_DEFAULT_PAGE_SIZE,
} as GetTimelineThreadsFromPersonIdQueryVariables; } as GetTimelineThreadsFromPersonIdQueryVariables;
const { data, loading, fetchMore, error } = useQuery(threadQuery, { const {
data,
loading: firstQueryLoading,
fetchMore,
error,
} = useQuery(threadQuery, {
variables: threadQueryVariables, variables: threadQueryVariables,
}); });
const fetchMoreRecords = async () => { const fetchMoreRecords = async () => {
if (emailThreadsPage.hasNextPage && !isFetchingMoreEmails) { if (
emailThreadsPage.hasNextPage &&
!isFetchingMoreEmails &&
!firstQueryLoading
) {
setIsFetchingMoreEmails(true); setIsFetchingMoreEmails(true);
await fetchMore({ await fetchMore({
@ -144,7 +153,7 @@ export const EmailThreads = ({
} }
fontColor={H1TitleFontColor.Primary} fontColor={H1TitleFontColor.Primary}
/> />
{!loading && ( {!firstQueryLoading && (
<Card> <Card>
{timelineThreads?.map((thread: TimelineThread, index: number) => ( {timelineThreads?.map((thread: TimelineThread, index: number) => (
<EmailThreadPreview <EmailThreadPreview
@ -157,7 +166,7 @@ export const EmailThreads = ({
</Card> </Card>
)} )}
<EmailThreadFetchMoreLoader <EmailThreadFetchMoreLoader
loading={isFetchingMoreEmails} loading={isFetchingMoreEmails || firstQueryLoading}
onLastRowVisible={fetchMoreRecords} onLastRowVisible={fetchMoreRecords}
/> />
</Section> </Section>