diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts index 8273caecb70c..d9dc4004e533 100644 --- a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts +++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts @@ -11,7 +11,7 @@ import { buildShowPageURL } from '@/object-record/record-show/utils/buildShowPag import { buildIndexTablePageURL } from '@/object-record/record-table/utils/buildIndexTableURL'; import { useQueryVariablesFromActiveFieldsOfViewOrDefaultView } from '@/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView'; import { isNonEmptyString } from '@sniptt/guards'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { capitalize } from '~/utils/string/capitalize'; export const useRecordShowPagePagination = ( @@ -60,55 +60,47 @@ export const useRecordShowPagePagination = ( const cursorFromRequest = currentRecordsPageInfo?.endCursor; - const { - loading: loadingRecordBefore, - records: recordsBefore, - totalCount: totalCountBefore, - } = useFindManyRecords({ - skip: loadingCursor, - fetchPolicy: 'network-only', - filter, - orderBy, - cursorFilter: isNonEmptyString(cursorFromRequest) - ? { - cursorDirection: 'before', - cursor: cursorFromRequest, - limit: 1, - } - : undefined, - objectNameSingular, - recordGqlFields, - }); - - const { - loading: loadingRecordAfter, - records: recordsAfter, - totalCount: totalCountAfter, - } = useFindManyRecords({ - skip: loadingCursor, - filter, - fetchPolicy: 'network-only', - orderBy, - cursorFilter: cursorFromRequest - ? { - cursorDirection: 'after', - cursor: cursorFromRequest, - limit: 1, - } - : undefined, - objectNameSingular, - recordGqlFields, - }); + const [totalCount, setTotalCount] = useState(0); - const [totalCount, setTotalCount] = useState( - Math.max(totalCountBefore ?? 0, totalCountAfter ?? 0), - ); + const { loading: loadingRecordBefore, records: recordsBefore } = + useFindManyRecords({ + skip: loadingCursor, + fetchPolicy: 'network-only', + filter, + orderBy, + cursorFilter: isNonEmptyString(cursorFromRequest) + ? { + cursorDirection: 'before', + cursor: cursorFromRequest, + limit: 1, + } + : undefined, + objectNameSingular, + recordGqlFields, + onCompleted: (_, pagination) => { + setTotalCount(pagination?.totalCount ?? 0); + }, + }); - useEffect(() => { - if (totalCountBefore !== undefined || totalCountAfter !== undefined) { - setTotalCount(Math.max(totalCountBefore ?? 0, totalCountAfter ?? 0)); - } - }, [totalCountBefore, totalCountAfter]); + const { loading: loadingRecordAfter, records: recordsAfter } = + useFindManyRecords({ + skip: loadingCursor, + filter, + fetchPolicy: 'network-only', + orderBy, + cursorFilter: cursorFromRequest + ? { + cursorDirection: 'after', + cursor: cursorFromRequest, + limit: 1, + } + : undefined, + objectNameSingular, + recordGqlFields, + onCompleted: (_, pagination) => { + setTotalCount(pagination?.totalCount ?? 0); + }, + }); const loading = loadingRecordAfter || loadingRecordBefore || loadingCursor; diff --git a/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx b/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx index fe407beafec4..30e73dad46ea 100644 --- a/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx +++ b/packages/twenty-front/src/pages/object-record/RecordShowPage.tsx @@ -3,16 +3,15 @@ import { useParams } from 'react-router-dom'; import { TimelineActivityContext } from '@/activities/timelineActivities/contexts/TimelineActivityContext'; import { RecordShowContainer } from '@/object-record/record-show/components/RecordShowContainer'; import { useRecordShowPage } from '@/object-record/record-show/hooks/useRecordShowPage'; -import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination'; import { RecordValueSetterEffect } from '@/object-record/record-store/components/RecordValueSetterEffect'; import { RecordFieldValueSelectorContextProvider } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext'; import { PageBody } from '@/ui/layout/page/PageBody'; import { PageContainer } from '@/ui/layout/page/PageContainer'; import { PageFavoriteButton } from '@/ui/layout/page/PageFavoriteButton'; -import { PageHeader } from '@/ui/layout/page/PageHeader'; import { ShowPageAddButton } from '@/ui/layout/show-page/components/ShowPageAddButton'; import { ShowPageMoreButton } from '@/ui/layout/show-page/components/ShowPageMoreButton'; import { PageTitle } from '@/ui/utilities/page-title/PageTitle'; +import { RecordShowPageHeader } from '~/pages/object-record/RecordShowPageHeader'; export const RecordShowPage = () => { const parameters = useParams<{ @@ -36,33 +35,15 @@ export const RecordShowPage = () => { parameters.objectRecordId ?? '', ); - const { - viewName, - hasPreviousRecord, - hasNextRecord, - navigateToPreviousRecord, - navigateToNextRecord, - navigateToIndexView, - } = useRecordShowPagePagination( - parameters.objectNameSingular ?? '', - parameters.objectRecordId ?? '', - ); - return ( - <> { objectNameSingular={objectNameSingular} /> - + { + const { + viewName, + hasPreviousRecord, + hasNextRecord, + navigateToPreviousRecord, + navigateToNextRecord, + navigateToIndexView, + } = useRecordShowPagePagination(objectNameSingular, objectRecordId); + + const { headerIcon } = useRecordShowPage(objectNameSingular, objectRecordId); + + return ( + + {children} + + ); +};