/* eslint-disable react/no-array-index-key */ import React from 'react'; import dayjs from 'dayjs'; import { FormattedMessage, useIntl } from 'dumi'; import { Tabs, Skeleton, Avatar, Divider, Empty } from 'antd'; import { css } from '@emotion/react'; import { useSiteData } from '../../../pages/index/components/util'; import type { Article, Authors } from '../../../pages/index/components/util'; import useSiteToken from '../../../hooks/useSiteToken'; const useStyle = () => { const { token } = useSiteToken(); 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; } ${antCls}-avatar > img { max-width: unset; } `, }; }; interface ArticleListProps { name: React.ReactNode; data: Article[]; authors: Authors; } const ArticleList: React.FC = ({ name, data = [], authors = [] }) => { const { articleList } = useStyle(); return (

{name}

); }; export default () => { const { locale } = useIntl(); const isZhCN = locale === 'zh-CN'; const [{ articles = { cn: [], en: [] }, authors = [] }, loading] = useSiteData(); const styles = useStyle(); // ========================== Data ========================== const mergedData = React.useMemo(() => { const yearData: Record> = {}; articles[isZhCN ? 'cn' : 'en']?.forEach((article) => { const year = dayjs(article.date).year(); yearData[year] = yearData[year] || {}; yearData[year][article.type] = [...(yearData[year][article.type] || []), article]; }); return yearData; }, [articles]); // ========================= Render ========================= let content: React.ReactNode; if (loading) { content = ; } else { const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a)); content = yearList.length ? ( {yearList.map((year) => ( } data={mergedData[year].design} authors={authors} /> } data={mergedData[year].develop} authors={authors} />
))}
) : null; } return (
{content}
); };