import React from 'react'; import { Avatar, List, Skeleton } from 'antd'; import classNames from 'classnames'; import styles from './NoticeList.less'; let ListElement = null; export default function NoticeList({ data = [], onClick, onClear, title, locale, emptyText, emptyImage, loading, onLoadMore, visible, loadedAll = true, scrollToLoad = true, showClear = true, skeletonCount = 5, skeletonProps = {}, }) { if (data.length === 0) { return (
{emptyImage ? not found : null}
{emptyText || locale.emptyText}
); } const loadingList = Array.from({ length: loading ? skeletonCount : 0 }).map(() => ({ loading })); const LoadMore = loadedAll ? (
{locale.loadedAll}
) : (
{locale.loadMore}
); const onScroll = event => { if (!scrollToLoad || loading || loadedAll) return; if (typeof onLoadMore !== 'function') return; const { currentTarget: t } = event; if (t.scrollHeight - t.scrollTop - t.clientHeight <= 40) { onLoadMore(event); ListElement = t; } }; if (!visible && ListElement) { try { ListElement.scrollTo(null, 0); } catch (err) { ListElement = null; } } return (
{[...data, ...loadingList].map((item, i) => { const itemCls = classNames(styles.item, { [styles.read]: item.read, }); // eslint-disable-next-line no-nested-ternary const leftIcon = item.avatar ? ( typeof item.avatar === 'string' ? ( ) : ( {item.avatar} ) ) : null; return ( onClick(item)}> {item.title}
{item.extra}
} description={
{item.description}
{item.datetime}
} /> ); })} {showClear ? (
{locale.clear} {title}
) : null} ); }