2021-03-19 23:03:04 +08:00
|
|
|
/* eslint-disable react/no-array-index-key */
|
|
|
|
import * as React from 'react';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { FormattedMessage, useIntl } from 'react-intl';
|
2021-06-15 19:15:41 +08:00
|
|
|
import { Tabs, Skeleton, Avatar, Divider, Empty } from 'antd';
|
2021-03-19 23:03:04 +08:00
|
|
|
import { useSiteData } from '../../Home/util';
|
|
|
|
import './index.less';
|
|
|
|
|
|
|
|
interface Author {
|
|
|
|
avatar: string;
|
|
|
|
href: string;
|
|
|
|
type: 'design' | 'develop';
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Article {
|
|
|
|
title: string;
|
|
|
|
href: string;
|
|
|
|
date: string;
|
|
|
|
type: 'design' | 'develop';
|
2021-05-29 23:59:30 +08:00
|
|
|
author: Author['name'];
|
2021-03-19 23:03:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Articles {
|
|
|
|
cn: Article[];
|
|
|
|
en: Article[];
|
|
|
|
}
|
|
|
|
|
2021-06-13 16:23:12 +08:00
|
|
|
type Authors = Author[];
|
2021-05-29 23:59:30 +08:00
|
|
|
|
2021-03-19 23:03:04 +08:00
|
|
|
interface ArticleListProps {
|
|
|
|
name: React.ReactNode;
|
|
|
|
data: Article[];
|
2021-05-29 23:59:30 +08:00
|
|
|
authors: Authors;
|
2021-03-19 23:03:04 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 19:15:41 +08:00
|
|
|
const ArticleList: React.FC<ArticleListProps> = ({ name, data = [], authors = [] }) => (
|
2021-03-19 23:03:04 +08:00
|
|
|
<td>
|
|
|
|
<h4>{name}</h4>
|
|
|
|
<ul className="article-list">
|
2021-06-15 19:15:41 +08:00
|
|
|
{data.length === 0 ? (
|
|
|
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
|
|
|
) : (
|
|
|
|
data.map((article, index) => {
|
|
|
|
const author = authors.find(auth => auth.name === article.author);
|
|
|
|
return (
|
|
|
|
<li key={index}>
|
|
|
|
<a href={author?.href} target="_blank" rel="noreferrer">
|
|
|
|
<Avatar size="small" src={author?.avatar} />
|
|
|
|
</a>
|
|
|
|
<Divider type="vertical" />
|
|
|
|
<a href={article.href} target="_blank" rel="noreferrer">
|
|
|
|
{article.title}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)}
|
2021-03-19 23:03:04 +08:00
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const { locale } = useIntl();
|
|
|
|
const isZhCN = locale === 'zh-CN';
|
2022-09-05 19:41:32 +08:00
|
|
|
const [{ articles = { cn: [], en: [] }, authors = [] }, loading] = useSiteData<{
|
|
|
|
articles: Articles;
|
|
|
|
authors: Authors;
|
|
|
|
}>();
|
2021-03-19 23:03:04 +08:00
|
|
|
|
|
|
|
// ========================== Data ==========================
|
|
|
|
const mergedData = React.useMemo(() => {
|
|
|
|
const yearData: Record<number | string, Record<string, Article[]>> = {};
|
2021-05-29 23:59:30 +08:00
|
|
|
articles[isZhCN ? 'cn' : 'en']?.forEach(article => {
|
2021-03-19 23:03:04 +08:00
|
|
|
const year = moment(article.date).year();
|
|
|
|
yearData[year] = yearData[year] || {};
|
|
|
|
yearData[year][article.type] = [...(yearData[year][article.type] || []), article];
|
|
|
|
});
|
|
|
|
return yearData;
|
2021-05-29 23:59:30 +08:00
|
|
|
}, [articles]);
|
2021-03-19 23:03:04 +08:00
|
|
|
|
|
|
|
// ========================= Render =========================
|
|
|
|
let content: React.ReactNode;
|
|
|
|
|
2021-05-29 23:59:30 +08:00
|
|
|
if (loading) {
|
2021-03-19 23:03:04 +08:00
|
|
|
content = <Skeleton active />;
|
|
|
|
} else {
|
|
|
|
const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a));
|
|
|
|
content = yearList.length ? (
|
|
|
|
<Tabs>
|
2021-05-29 23:59:30 +08:00
|
|
|
{yearList.map(year => (
|
|
|
|
<Tabs.TabPane tab={`${year}${isZhCN ? ' 年' : ''}`} key={year}>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<ArticleList
|
|
|
|
name={<FormattedMessage id="app.docs.resource.design" />}
|
|
|
|
data={mergedData[year].design}
|
|
|
|
authors={authors}
|
|
|
|
/>
|
|
|
|
<ArticleList
|
|
|
|
name={<FormattedMessage id="app.docs.resource.develop" />}
|
|
|
|
data={mergedData[year].develop}
|
|
|
|
authors={authors}
|
|
|
|
/>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</Tabs.TabPane>
|
|
|
|
))}
|
2021-03-19 23:03:04 +08:00
|
|
|
</Tabs>
|
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="articles" className="antd-articles">
|
|
|
|
{content}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|