diff --git a/src/client/components/SimpleVirtualList.tsx b/src/client/components/SimpleVirtualList.tsx index 7768ed5..91a6d2a 100644 --- a/src/client/components/SimpleVirtualList.tsx +++ b/src/client/components/SimpleVirtualList.tsx @@ -1,5 +1,6 @@ import { useWatch } from '@/hooks/useWatch'; -import { VirtualItem, useVirtualizer } from '@tanstack/react-virtual'; +import { useTranslation } from '@i18next-toolkit/react'; +import { useVirtualizer } from '@tanstack/react-virtual'; import { Empty } from 'antd'; import { last } from 'lodash-es'; import React, { useRef } from 'react'; @@ -9,8 +10,9 @@ interface VirtualListProps { hasNextPage: boolean | undefined; isFetchingNextPage: boolean; onFetchNextPage: () => void; - estimateSize: (index: number) => number; - renderItem: (item: VirtualItem) => React.ReactElement; + estimateSize: number; + renderItem: (item: T) => React.ReactElement; + renderEmpty?: () => React.ReactElement; } export const SimpleVirtualList: React.FC = React.memo( (props) => { @@ -21,14 +23,15 @@ export const SimpleVirtualList: React.FC = React.memo( onFetchNextPage, estimateSize, renderItem, + renderEmpty, } = props; const parentRef = useRef(null); - + const { t } = useTranslation(); const rowVirtualizer = useVirtualizer({ count: hasNextPage ? allData.length + 1 : allData.length, getScrollElement: () => parentRef.current, - estimateSize, + estimateSize: () => estimateSize, overscan: 5, }); @@ -52,7 +55,7 @@ export const SimpleVirtualList: React.FC = React.memo( return (
- {virtualItems.length === 0 && } + {virtualItems.length === 0 && (renderEmpty ? renderEmpty() : )}
= React.memo( height: `${rowVirtualizer.getTotalSize()}px`, }} > - {virtualItems.map((virtualItem) => renderItem(virtualItem))} + {virtualItems.map((virtualItem) => { + const isLoaderRow = virtualItem.index > allData.length - 1; + const data = allData[virtualItem.index]; + + return ( +
+ {isLoaderRow + ? hasNextPage + ? t('Loading more...') + : t('Nothing more to load') + : renderItem(data)} +
+ ); + })}
); diff --git a/src/client/routes/settings/auditLog.tsx b/src/client/routes/settings/auditLog.tsx index f9564ff..2fb4591 100644 --- a/src/client/routes/settings/auditLog.tsx +++ b/src/client/routes/settings/auditLog.tsx @@ -26,9 +26,14 @@ function PageComponent() { const parentRef = useRef(null); const { data, hasNextPage, fetchNextPage, isFetchingNextPage } = - trpc.auditLog.fetchByCursor.useInfiniteQuery({ - workspaceId, - }); + trpc.auditLog.fetchByCursor.useInfiniteQuery( + { + workspaceId, + }, + { + getNextPageParam: (lastPage) => lastPage.nextCursor, + } + ); const allData = useMemo(() => { if (!data) { @@ -65,57 +70,31 @@ function PageComponent() { return ( }> - - - 48} - renderItem={(item) => { - const isLoaderRow = item.index > allData.length - 1; - const data = allData[item.index]; - - return ( - + { + return ( +
+ {item.relatedType && } +
- {isLoaderRow ? ( - hasNextPage ? ( - t('Loading more...') - ) : ( - t('Nothing more to load') - ) - ) : ( -
- {data.relatedType && ( - - )} -
- {dayjs(data.createdAt).format('MM-DD HH:mm')} -
-
- {data.content} -
-
- )} - - ); - }} - /> - - + {dayjs(item.createdAt).format('MM-DD HH:mm')} +
+
+ {item.content} +
+
+ ); + }} + /> +
); }