fix: EmailThreads and Calendar making one extra graphql requests even total records are fetched (#6814)

## ISSUE (BUG)
- Closes #5282

## Description
- [x] Email Threads Tab was making two graphql requests
**[GetTimelineThreadsFromCompanyId]** when navigating after a first
render of record page, once only, later it was making only one.
- [x] Similarly Calendar Tab
**[GetTimelineCalendarEventsFromCompanyId]**

### Before


https://github.com/user-attachments/assets/c234b7b4-fe7d-4655-92d6-0a6817fda6b5


### After 


https://github.com/user-attachments/assets/80af33c7-b801-4377-a59a-47c43e0fecdd

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Nabhag Motivaras
2024-08-31 17:52:33 +05:30
committed by GitHub
parent e903ce398e
commit ea7b9e90c9
2 changed files with 24 additions and 3 deletions

View File

@ -63,7 +63,18 @@ export const Calendar = ({
TIMELINE_CALENDAR_EVENTS_DEFAULT_PAGE_SIZE, TIMELINE_CALENDAR_EVENTS_DEFAULT_PAGE_SIZE,
); );
const { timelineCalendarEvents } = data?.[queryName] ?? {}; const { timelineCalendarEvents, totalNumberOfCalendarEvents } =
data?.[queryName] ?? {};
const hasMoreCalendarEvents =
timelineCalendarEvents && totalNumberOfCalendarEvents
? timelineCalendarEvents?.length < totalNumberOfCalendarEvents
: false;
const handleLastRowVisible = async () => {
if (hasMoreCalendarEvents) {
await fetchMoreRecords();
}
};
const { const {
calendarEventsByDayTime, calendarEventsByDayTime,
@ -134,7 +145,7 @@ export const Calendar = ({
})} })}
<CustomResolverFetchMoreLoader <CustomResolverFetchMoreLoader
loading={isFetchingMore || firstQueryLoading} loading={isFetchingMore || firstQueryLoading}
onLastRowVisible={fetchMoreRecords} onLastRowVisible={handleLastRowVisible}
/> />
</StyledContainer> </StyledContainer>
</CalendarContext.Provider> </CalendarContext.Provider>

View File

@ -60,6 +60,16 @@ export const EmailThreads = ({
); );
const { totalNumberOfThreads, timelineThreads } = data?.[queryName] ?? {}; const { totalNumberOfThreads, timelineThreads } = data?.[queryName] ?? {};
const hasMoreTimelineThreads =
timelineThreads && totalNumberOfThreads
? timelineThreads?.length < totalNumberOfThreads
: false;
const handleLastRowVisible = async () => {
if (hasMoreTimelineThreads) {
await fetchMoreRecords();
}
};
if (firstQueryLoading) { if (firstQueryLoading) {
return <SkeletonLoader />; return <SkeletonLoader />;
@ -108,7 +118,7 @@ export const EmailThreads = ({
)} )}
<CustomResolverFetchMoreLoader <CustomResolverFetchMoreLoader
loading={isFetchingMore || firstQueryLoading} loading={isFetchingMore || firstQueryLoading}
onLastRowVisible={fetchMoreRecords} onLastRowVisible={handleLastRowVisible}
/> />
</Section> </Section>
</StyledContainer> </StyledContainer>