@@ -5,10 +5,9 @@ import { useTranslations } from 'next-intl';
55import Link from 'next/link' ;
66import React , { useEffect , useState } from 'react' ;
77
8- import { LocaleTime } from '@/components/LocaleTime' ;
98import { useAsyncLoading } from '@/hooks/useAsyncLoading' ;
109import { ArticleProvider } from '@/providers/article' ;
11- import { LikeOutlined } from '@ant-design/icons' ;
10+ import { LikeOutlined , EyeOutlined } from '@ant-design/icons' ;
1211
1312import style from './index.module.scss' ;
1413
@@ -22,12 +21,14 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
2221 const t = useTranslations ( ) ;
2322 const [ getRecommend , loading ] = useAsyncLoading ( ArticleProvider . getRecommend , 150 , true ) ;
2423 const [ fetched , setFetched ] = useState ( '' ) ;
25- const [ articles , setArticles ] = useState ( [ ] ) ;
24+ const [ articles , setArticles ] = useState < IArticle [ ] > ( [ ] ) ;
2625
2726 useEffect ( ( ) => {
2827 if ( fetched === articleId ) return ;
2928 getRecommend ( articleId ) . then ( ( res ) => {
30- setArticles ( res . slice ( 0 , 6 ) ) ;
29+ const articles = res . slice ( 0 , 6 ) ;
30+ articles . sort ( ( a , b ) => b . views - a . views ) ;
31+ setArticles ( articles ) ;
3132 setFetched ( articleId ) ;
3233 } ) ;
3334 } , [ articleId , getRecommend , fetched ] ) ;
@@ -36,7 +37,7 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
3637 < div className = { cls ( style . wrapper , mode === 'inline' && style . inline ) } >
3738 { needTitle && (
3839 < div className = { style . title } >
39- < LikeOutlined className = { style . recommendIcon } />
40+ < LikeOutlined className = { style . recommendIcon } />
4041 < span > { t ( 'recommendToReading' ) } </ span >
4142 </ div >
4243 ) }
@@ -53,15 +54,17 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
5354 )
5455 ) : (
5556 < ul className = { style . inlineWrapper } >
56- { articles . map ( ( article ) => {
57+ { articles . map ( ( article , index ) => {
5758 return (
5859 < li key = { article . id } >
5960 < Link href = { `/article/[id]` } as = { `/article/${ article . id } ` } scroll = { false } >
60- < a >
61- < span > { article . title } </ span >
62- { ' · ' }
63- < span >
64- < LocaleTime date = { article . publishAt } timeago = { true } />
61+ < a className = { style . article } title = { article . title } >
62+ < span className = { style . articleTitle } data-num = { index + 1 } >
63+ < span > { article . title } </ span >
64+ </ span >
65+ < span className = { style . views } >
66+ < EyeOutlined />
67+ < span className = { style . number } > { article . views } </ span >
6568 </ span >
6669 </ a >
6770 </ Link >
0 commit comments