import { FC, useMemo } from 'react'; import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso'; import Card from '@/components/Movie/Card'; import { showPreviewModal } from '@/components/Movie/Preview'; import filterUnknownMovies from '@/lib/filterUnknownMovies'; interface Props { type?: ShowType; pages: Array; hasNextPage?: boolean; customScrollParent?: HTMLElement; fetchNextPage?: () => void; onPreviewClose?: () => void; } const components: VirtuosoGridProps void }>['components'] = { Item: ({ context, 'data-index': index }) => { const { shows, onClick } = context || {}; const movie = shows?.[index]; return onClick?.(movie!)} />; } }; const List: FC = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, type = 'movie', customScrollParent }) => { const shows = useMemo( () => pages?.reduce((shows, page) => { shows.push(...filterUnknownMovies(page.results)); return shows; }, [] as Movie[]) || [], [pages] ); if (!shows.length) return null; const context = { shows, onClick: (movie: Movie) => showPreviewModal({ movie, onClose: onPreviewClose, type }) }; const handleFetchMore = () => { if (!hasNextPage) return; fetchNextPage?.(); }; return ( <>
); }; export default List;