Files
supabase/apps/studio/components/interfaces/Storage/FilesBuckets/BucketsTable.LoadMoreRow.tsx
Charis 73c834001c feat(storage): use pagination for storage bucket list (#40695)
The bucket list endpoint now accepts pagination options. Adapting the
storage buckets table UI to paginate in pages of 100 buckets at a time,
with infinite loading/scrolling.
2025-12-03 13:16:40 -05:00

47 lines
1.4 KiB
TypeScript

import { useIntersectionObserver } from '@uidotdev/usehooks'
import { VirtualizedTableCell, VirtualizedTableRow } from 'components/ui/VirtualizedTable'
import { useEffect, type ReactNode } from 'react'
import { TableCell, TableRow } from 'ui'
import { ShimmeringLoader } from 'ui-patterns'
import type { BucketsTablePaginationProps } from './BucketsTable.types'
type LoadMoreRowProps = {
mode: 'standard' | 'virtualized'
colSpan: number
} & BucketsTablePaginationProps
export const LoadMoreRow = ({
mode,
colSpan,
hasMore = false,
isLoadingMore = false,
onLoadMore,
}: LoadMoreRowProps): ReactNode => {
const [sentinelRef, entry] = useIntersectionObserver({
threshold: 0,
rootMargin: '200px 0px 200px 0px',
})
useEffect(() => {
if (entry?.isIntersecting && hasMore && !isLoadingMore) {
onLoadMore?.()
}
}, [entry?.isIntersecting, hasMore, isLoadingMore, onLoadMore])
if (!hasMore && !isLoadingMore) return null
const RowComponent = mode === 'standard' ? TableRow : VirtualizedTableRow
const CellComponent = mode === 'standard' ? TableCell : VirtualizedTableCell
return (
<RowComponent ref={sentinelRef}>
{Array.from({ length: colSpan }, (_, idx) => (
<CellComponent key={idx}>
{idx !== 0 && idx !== colSpan - 1 && <ShimmeringLoader className="w-3/4" />}
</CellComponent>
))}
</RowComponent>
)
}