docs: fix articles empty bug

This commit is contained in:
afc163 2021-06-15 19:15:41 +08:00
parent 34d7a1c80c
commit c5dfd61cf5

View File

@ -2,7 +2,7 @@
import * as React from 'react';
import moment from 'moment';
import { FormattedMessage, useIntl } from 'react-intl';
import { Tabs, Skeleton, Avatar, Divider } from 'antd';
import { Tabs, Skeleton, Avatar, Divider, Empty } from 'antd';
import { useSiteData } from '../../Home/util';
import './index.less';
@ -34,24 +34,28 @@ interface ArticleListProps {
authors: Authors;
}
const ArticleList: React.FC<ArticleListProps> = ({ name, data, authors = [] }) => (
const ArticleList: React.FC<ArticleListProps> = ({ name, data = [], authors = [] }) => (
<td>
<h4>{name}</h4>
<ul className="article-list">
{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>
);
})}
{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>
);
})
)}
</ul>
</td>
);