|
1 | | -import { Card, FloatingFilter } from 'src/components/Elements' |
| 1 | +import { useCallback } from 'react' |
| 2 | +import { Card } from 'src/components/Elements' |
2 | 3 | import { ListPostComponent } from 'src/components/List/ListPostComponent' |
3 | 4 | import { Article, CardPropsType } from 'src/types' |
4 | 5 | import { useGetSourceArticles } from '../../api/getSourceArticles' |
5 | 6 | import { useSelectedTags } from '../../hooks/useSelectedTags' |
6 | | -import { CardHeader } from '../CardHeader' |
7 | | -import { CardSettings } from '../CardSettings' |
| 7 | +import { MemoizedCardHeader } from '../CardHeader' |
| 8 | +import { MemoizedCardSettings } from '../CardSettings' |
8 | 9 | import ArticleItem from './ArticleItem' |
9 | 10 |
|
10 | | -const GLOBAL_TAG = { label: 'Global', value: 'programming' } |
| 11 | +const GLOBAL_TAG = { label: 'Global', value: 'global' } |
11 | 12 |
|
12 | 13 | export function FreecodecampCard(props: CardPropsType) { |
13 | 14 | const { meta } = props |
14 | | - const { queryTags, selectedTag, cardSettings } = useSelectedTags({ |
| 15 | + const { |
| 16 | + queryTags, |
| 17 | + selectedTag, |
| 18 | + cardSettings: { sortBy, language } = {}, |
| 19 | + } = useSelectedTags({ |
15 | 20 | source: meta.value, |
16 | 21 | fallbackTag: GLOBAL_TAG, |
17 | 22 | }) |
18 | 23 |
|
19 | 24 | const { data, isLoading } = useGetSourceArticles({ |
20 | 25 | source: 'freecodecamp', |
21 | | - tags: queryTags.map((tag) => tag.value), |
| 26 | + tags: queryTags, |
22 | 27 | }) |
23 | 28 |
|
24 | | - const renderItem = (item: Article, index: number) => ( |
25 | | - <ArticleItem item={item} key={`fcc-${index}`} index={index} analyticsTag={meta.analyticsTag} /> |
| 29 | + const renderItem = useCallback( |
| 30 | + (item: Article) => <ArticleItem item={item} key={item.id} analyticsTag={meta.analyticsTag} />, |
| 31 | + [meta.analyticsTag] |
26 | 32 | ) |
27 | 33 |
|
28 | 34 | return ( |
29 | 35 | <Card |
30 | 36 | titleComponent={ |
31 | | - <CardHeader label={meta.label} fallbackTag={GLOBAL_TAG} selectedTag={selectedTag} /> |
| 37 | + <MemoizedCardHeader label={meta.label} fallbackTag={GLOBAL_TAG} selectedTag={selectedTag} /> |
32 | 38 | } |
33 | 39 | settingsComponent={ |
34 | | - <CardSettings |
| 40 | + <MemoizedCardSettings |
35 | 41 | url={meta.link} |
36 | 42 | id={meta.value} |
37 | 43 | globalTag={GLOBAL_TAG} |
38 | | - sortBy={cardSettings?.sortBy} |
39 | | - language={cardSettings?.language || GLOBAL_TAG.value} |
| 44 | + sortBy={sortBy} |
| 45 | + language={language || GLOBAL_TAG.value} |
40 | 46 | showDateRangeFilter={false} |
41 | 47 | /> |
42 | 48 | } |
43 | 49 | {...props}> |
44 | | - <FloatingFilter card={meta} filters={['language']} /> |
45 | 50 | <ListPostComponent |
46 | | - sortBy={cardSettings?.sortBy as keyof Article} |
| 51 | + sortBy={sortBy as keyof Article} |
47 | 52 | items={data} |
48 | 53 | isLoading={isLoading} |
49 | 54 | renderItem={renderItem} |
|
0 commit comments