@@ -7,11 +7,45 @@ import { useMemo, useState } from 'react';
77import { groupBy } from 'lodash' ;
88import { BASE_NAV_ROUTE } from '@router' ;
99
10+ const CategoryButton = ( {
11+ category,
12+ setCategory,
13+ secondPath,
14+ isSelected,
15+ } : {
16+ category : string ;
17+ setCategory : ( category : string ) => void ;
18+ secondPath : string ;
19+ isSelected : boolean ;
20+ } ) => {
21+ const navigate = useNavigate ( ) ;
22+ return (
23+ < Button
24+ w = { '100%' }
25+ color = { 'white' }
26+ py = { 3 }
27+ px = { 5 }
28+ bg = { isSelected ? 'gray.800' : '' }
29+ fontSize = { 20 }
30+ variant = { 'ghost' }
31+ border = { '1px solid gray' }
32+ _hover = { { bg : 'gray.600' , cursor : 'pointer' , color : 'violet' } }
33+ onClick = { ( ) => {
34+ if ( secondPath ) {
35+ navigate ( BASE_NAV_ROUTE + 'articles' ) ;
36+ }
37+ setCategory ( category ) ;
38+ } }
39+ >
40+ { category }
41+ </ Button >
42+ ) ;
43+ } ;
44+
1045const ArticlesScreen = ( ) => {
1146 const { data } = useGetArticlesData ( ) ;
1247 const location = useLocation ( ) ;
13- const navigate = useNavigate ( ) ;
14- const [ category , setCategory ] = useState ( '' ) ;
48+ const [ category , setCategory ] = useState ( 'All' ) ;
1549 const secondPath = location . pathname . split ( '/' ) [ 3 ] ;
1650
1751 const articles = useMemo (
@@ -61,29 +95,21 @@ const ArticlesScreen = () => {
6195 top = { '12vh' }
6296 marginTop = { '12vh' }
6397 >
98+ < CategoryButton
99+ category = { 'All' }
100+ setCategory = { setCategory }
101+ secondPath = { secondPath }
102+ isSelected = { 'All' === category }
103+ />
64104 { Object . keys ( filteredArticles ) . map (
65105 ( group_name : any , index : number ) => (
66- < Button
67- w = { '100%' }
106+ < CategoryButton
68107 key = { index }
69- py = { 3 }
70- color = { 'white' }
71- px = { 5 }
72- bg = { group_name === category ? 'gray.800' : '' }
73- fontSize = { 20 }
74- m = { 0 }
75- variant = { 'ghost' }
76- border = { '1px solid gray' }
77- _hover = { { bg : 'gray.600' , cursor : 'pointer' , color : 'violet' } }
78- onClick = { ( ) => {
79- if ( secondPath ) {
80- navigate ( BASE_NAV_ROUTE + 'articles' ) ;
81- }
82- setCategory ( group_name ) ;
83- } }
84- >
85- { group_name }
86- </ Button >
108+ category = { group_name }
109+ setCategory = { setCategory }
110+ secondPath = { secondPath }
111+ isSelected = { group_name === category }
112+ />
87113 ) ,
88114 ) }
89115 </ VStack >
@@ -102,9 +128,12 @@ const ArticlesScreen = () => {
102128 justify = "start"
103129 justifyContent = { 'space-between' }
104130 >
105- { ( category ? filteredArticles [ category ] : articles ) ?. map (
106- ( article : any ) => < ArticleCard key = { article . id } { ...article } /> ,
107- ) }
131+ { ( category && category !== 'All'
132+ ? filteredArticles [ category ]
133+ : articles
134+ ) ?. map ( ( article : any ) => (
135+ < ArticleCard key = { article . id } { ...article } />
136+ ) ) }
108137 </ Wrap >
109138 ) }
110139 { secondPath && < MarkdownViewer articleKey = { secondPath } /> }
0 commit comments