1+ import { useCallback } from 'react'
12import { AiOutlineLike } from 'react-icons/ai'
23import { BiCommentDetail } from 'react-icons/bi'
3- import { Card , FloatingFilter } from 'src/components/Elements'
4+ import { Card } from 'src/components/Elements'
45import { ListPostComponent } from 'src/components/List/ListPostComponent'
56import { Article , CardPropsType } from 'src/types'
67import { useGetSourceArticles } from '../../api/getSourceArticles'
78import { useSelectedTags } from '../../hooks/useSelectedTags'
8- import { CardHeader } from '../CardHeader'
9- import { CardSettings } from '../CardSettings'
9+ import { MemoizedCardHeader } from '../CardHeader'
10+ import { MemoizedCardSettings } from '../CardSettings'
1011import ArticleItem from './ArticleItem'
1112
1213const GLOBAL_TAG = { label : 'Global' , value : 'programming' }
1314
1415export function DevtoCard ( props : CardPropsType ) {
1516 const { meta } = props
1617
17- const { queryTags, selectedTag, cardSettings } = useSelectedTags ( {
18+ const {
19+ queryTags,
20+ selectedTag,
21+ cardSettings : { sortBy, language } = { } ,
22+ } = useSelectedTags ( {
1823 source : meta . value ,
1924 fallbackTag : GLOBAL_TAG ,
2025 } )
@@ -25,25 +30,26 @@ export function DevtoCard(props: CardPropsType) {
2530 isLoading,
2631 } = useGetSourceArticles ( {
2732 source : 'devto' ,
28- tags : queryTags . map ( ( tag ) => tag . value ) ,
33+ tags : queryTags ,
2934 } )
3035
31- const renderItem = ( item : Article , index : number ) => (
32- < ArticleItem item = { item } key = { `at-${ index } ` } index = { index } analyticsTag = { meta . analyticsTag } />
36+ const renderItem = useCallback (
37+ ( item : Article ) => < ArticleItem item = { item } key = { item . id } analyticsTag = { meta . analyticsTag } /> ,
38+ [ meta . analyticsTag ]
3339 )
3440
3541 return (
3642 < Card
3743 titleComponent = {
38- < CardHeader label = { meta . label } fallbackTag = { GLOBAL_TAG } selectedTag = { selectedTag } />
44+ < MemoizedCardHeader label = { meta . label } fallbackTag = { GLOBAL_TAG } selectedTag = { selectedTag } />
3945 }
4046 settingsComponent = {
41- < CardSettings
47+ < MemoizedCardSettings
4248 url = { meta . link }
4349 id = { meta . value }
4450 globalTag = { GLOBAL_TAG }
45- sortBy = { cardSettings ?. sortBy }
46- language = { cardSettings ?. language || GLOBAL_TAG . value }
51+ sortBy = { sortBy }
52+ language = { language || GLOBAL_TAG . value }
4753 sortOptions = { ( defaults ) => [
4854 ...defaults ,
4955 {
@@ -60,9 +66,8 @@ export function DevtoCard(props: CardPropsType) {
6066 />
6167 }
6268 { ...props } >
63- < FloatingFilter card = { meta } filters = { [ 'language' ] } />
6469 < ListPostComponent
65- sortBy = { cardSettings ?. sortBy as keyof Article }
70+ sortBy = { sortBy as keyof Article }
6671 items = { results }
6772 error = { error }
6873 isLoading = { isLoading }
0 commit comments