refactor: clean code and remove unnecessary dependencies
This commit is contained in:
1 parent
eceae6fec7
commit
ebf599eed6
92 files changed
+1152
-2842
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { FC } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
customScrollParent?: HTMLElement;
|
||||
fetchNextPage?: () => void;
|
||||
onPreviewClose?: () => void;
|
||||
}
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Show[]; onClick: (show: Show) => void }>['components'] = {
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context!;
|
||||
const show = shows?.[index];
|
||||
|
||||
if (!show) return null;
|
||||
|
||||
return <Card show={show} onClick={() => onClick?.(show)} />;
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({ shows, fetchNextPage, onPreviewClose, customScrollParent }) => {
|
||||
if (!shows.length) return null;
|
||||
|
||||
const context = {
|
||||
shows,
|
||||
onClick: (show: Show) => showPreviewModal({ show, onClose: onPreviewClose })
|
||||
};
|
||||
|
||||
const handleFetchMore = () => fetchNextPage?.();
|
||||
|
||||
return (
|
||||
<>
|
||||
<VirtuosoGrid
|
||||
useWindowScroll
|
||||
initialItemCount={20}
|
||||
overscan={10}
|
||||
data={shows}
|
||||
context={context}
|
||||
components={components}
|
||||
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden opacity-0 animate-fade-in-slide-in'
|
||||
customScrollParent={customScrollParent}
|
||||
endReached={handleFetchMore}
|
||||
/>
|
||||
<div className='h-2 w-full' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
||||
Reference in new issue
Block a user