/* eslint-disable react/no-array-index-key */ import * as React from 'react'; import { Suspense } from 'react'; import dayjs from 'dayjs'; import { FormattedMessage } from 'dumi'; import { createStyles } from 'antd-style'; import { Avatar, Divider, Empty, Skeleton, Tabs } from 'antd'; import type { Article, Authors } from '../../../pages/index/components/util'; import { useSiteData } from '../../../pages/index/components/util'; import useLocale from '../../../hooks/useLocale'; const useStyle = createStyles(({ token, css }) => { const { antCls } = token; return { articles: css` h4 { margin: 40px 0 24px; font-weight: 500; font-size: 20px; } ${antCls}-skeleton { h3 { margin: 0; } ul li { display: block; margin-left: 0; } } ${antCls}-tabs-nav::before { display: none; } table { width: 100%; table-layout: fixed; td { width: 50%; vertical-align: top; } } `, articleList: css` li { margin: 1em 0; padding: 0; font-size: 14px; list-style: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } ${antCls}-avatar > img { max-width: unset; } `, }; }); interface ArticleListProps { name: React.ReactNode; data: Article[]; authors: Authors; } const ArticleList: React.FC = ({ name, data = [], authors = [] }) => { const { styles } = useStyle(); return (

{name}

); }; const Articles: React.FC = () => { const [, lang] = useLocale(); const isZhCN = lang === 'cn'; const { articles = { cn: [], en: [] }, authors = [] } = useSiteData(); // ========================== Data ========================== const mergedData = React.useMemo(() => { const yearData: Record> = {}; articles[lang]?.forEach((article) => { const year = dayjs(article.date).year(); yearData[year] = yearData[year] || {}; yearData[year][article.type] = [...(yearData[year][article.type] || []), article]; }); return yearData; }, [articles]); const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a)); if (yearList.length === 0) { return null; } return ( ({ key: year, label: `${year}${isZhCN ? ' 年' : ''}`, children: ( } data={mergedData[year].design} authors={authors} /> } data={mergedData[year].develop} authors={authors} />
), }))} /> ); }; export default () => { const { styles } = useStyle(); return (
}>
); };