You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

5 years ago
import * as React from 'react';
import classNames from 'classnames';
import { FormattedMessage, useIntl } from 'react-intl';
import { Row, Col, Typography, Spin } from 'antd';
import { useSiteData } from './util';
5 years ago
import './RecommendPage.less';
const { Title, Paragraph } = Typography;
interface Recommend {
title?: string;
img?: string;
href?: string;
5 years ago
popularize?: boolean;
description?: string;
loading?: boolean;
5 years ago
}
interface RecommendBlockProps extends Recommend {
main?: boolean;
}
const RecommendBlock = ({
main,
title,
popularize,
description,
img,
href,
loading,
5 years ago
}: RecommendBlockProps) => {
return (
<a
className={classNames('recommend-block', {
'recommend-block-main': !!main,
'recommend-block-loading': loading,
})}
5 years ago
href={href}
target="_blank"
rel="noopener noreferrer"
onClick={() => {
window?.gtag('event', '点击', {
event_category: '首页推广',
event_label: href,
});
}}
5 years ago
>
<img src={img} alt={title} />
{popularize && (
<span className="recommend-popularize">
<FormattedMessage id="app.home.popularize" />
</span>
)}
<div className="recommend-content">
<Title level={4}>{title}</Title>
<Paragraph style={{ fontSize: 13 }}>{description}</Paragraph>
5 years ago
</div>
</a>
);
};
export default function RecommendPageo() {
const { locale } = useIntl();
const isZhCN = locale === 'zh-CN';
const list = useSiteData<Recommend[]>('recommendations', isZhCN ? 'cn' : 'en');
const isLoading = !list;
console.log(list);
5 years ago
return (
<Row gutter={[24, 24]} style={{ marginBottom: -36 }}>
<Col xs={24} sm={14}>
<RecommendBlock {...(list ? list[0] : {})} main loading={isLoading} />
</Col>
<Col xs={24} sm={10}>
<Row gutter={[24, 24]}>
<Col span={24}>
<RecommendBlock {...(list ? list[1] : {})} loading={isLoading} />
5 years ago
</Col>
<Col span={24}>
<RecommendBlock {...(list ? list[2] : {})} loading={isLoading} />
5 years ago
</Col>
</Row>
</Col>
5 years ago
</Row>
);
}