1- import { EyeOutlined , HeartOutlined , HistoryOutlined } from '@ant-design/icons' ;
2- import { Divider } from 'antd' ;
1+ import { EyeOutlined , FolderOutlined , HeartOutlined , HistoryOutlined } from '@ant-design/icons' ;
2+ import { Spin , Tag } from 'antd' ;
33import { useTranslations } from 'next-intl' ;
44import Link from 'next/link' ;
5- import React from 'react' ;
5+ import React , { useContext } from 'react' ;
66import LazyLoad from 'react-lazyload' ;
77import LogoSvg from '../../assets/LogoSvg' ;
88
99import { LocaleTime } from '@/components/LocaleTime' ;
1010
11+ import { GlobalContext } from '@/context/global' ;
12+ import { getColorFromNumber } from '@/utils' ;
1113import style from './index.module.scss' ;
1214
1315interface IProps {
@@ -18,16 +20,18 @@ interface IProps {
1820
1921export const ArticleList : React . FC < IProps > = ( { articles = [ ] } ) => {
2022 const t = useTranslations ( ) ;
23+ const { categories } = useContext ( GlobalContext ) ;
2124
2225 return (
2326 < div className = { style . wrapper } >
2427 { articles && articles . length ? (
25- articles . map ( ( article ) => {
28+ articles . map ( ( article : IArticle ) => {
29+ const categoryIndex = categories ?. findIndex ( ( category ) => category ?. value === article ?. category ?. value ) ;
2630 return (
2731 < div key = { article . id } className = { style . articleItem } >
2832 < div className = { style . coverWrapper } >
2933 { article . cover ? (
30- < LazyLoad height = { 120 } >
34+ < LazyLoad height = { 120 } placeholder = { < Spin /> } >
3135 < div className = { style . coverWrapper } >
3236 < Link href = { `/article/[id]` } as = { `/article/${ article . id } ` } scroll = { false } >
3337 < img src = { article . cover } alt = "cover" />
@@ -44,11 +48,11 @@ export const ArticleList: React.FC<IProps> = ({ articles = [] }) => {
4448 < header >
4549 < div className = { style . title } > { article . title } </ div >
4650 < div className = { style . info } >
47- { article . category && (
48- < >
49- < Divider type = "vertical" />
51+ { article . category && categoryIndex >= 0 && (
52+ < Tag className = { style . antBadge } color = { getColorFromNumber ( categoryIndex ) } >
53+ < FolderOutlined />
5054 < span className = { style . category } > { article . category ?. label } </ span >
51- </ >
55+ </ Tag >
5256 ) }
5357 </ div >
5458 </ header >
0 commit comments