import cx from 'clsx'; import { ReactNode } from 'react'; import SimpleBar from 'simplebar-react'; import { Placeholder } from '@/entities/placeholder'; import { Observer } from './observer'; import styles from './list.module.scss'; type Item = T extends (infer U)[] ? U : never; type Props = { items: T | undefined; hasMore: boolean; isLoading: boolean; noItems: { heading: string; subheading?: string }; size?: 'small' | 'large'; renderItem: (item: Item) => ReactNode; fetchMore: () => void; renderSkeleton: () => ReactNode; }; function List({ items, hasMore, isLoading, noItems, size = 'large', renderItem, fetchMore, renderSkeleton, }: Props) { // TODO: replace key with id const renderItems = () => items?.map((item, index) =>
  • {renderItem(item as Item)}
  • ); const count = items?.length; const isEmpty = !isLoading && !count; if (isLoading || isEmpty) return (
    ); return ( // TODO: add loading and empty states, // TODO: replace simplebar with css?
      {renderItems()}
    {hasMore && }
    ); } export { List };