Skip to content

Commit c528af4

Browse files
committed
use generic Item type
1 parent 615b29a commit c528af4

23 files changed

Lines changed: 100 additions & 105 deletions

File tree

src/features/conferencesCard/components/ConferenceItem.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { CardLink } from 'src/components/Elements'
22
import CardItemWithActions from 'src/components/CardItemWithActions'
33
import { Attributes } from 'src/lib/analytics'
4-
import { ConferenceItemPropsType } from 'src/types'
4+
import { BaseItemPropsType, Conference } from 'src/types'
55
import { MdAccessTime } from 'react-icons/md'
66
import { ColoredLanguagesBadge } from 'src/components/Elements'
77
import { flag } from 'country-emoji'
88
import { IoIosPin } from 'react-icons/io'
99
import { RiCalendarEventFill } from 'react-icons/ri'
10+
import { useUserPreferences } from 'src/stores/preferences'
1011

11-
const ConferencesItem = (props: ConferenceItemPropsType) => {
12-
const { item, index, listingMode } = props
12+
const ConferencesItem = ({ item, index, analyticsTag }: BaseItemPropsType<Conference>) => {
13+
const { listingMode } = useUserPreferences()
1314

1415
const ConferenceLocation = () => {
1516
if (item.online) {
@@ -53,7 +54,7 @@ const ConferencesItem = (props: ConferenceItemPropsType) => {
5354
}
5455
return (
5556
<CardItemWithActions
56-
source={'conferences'}
57+
source={analyticsTag}
5758
index={index}
5859
key={index}
5960
item={item}
@@ -65,7 +66,7 @@ const ConferencesItem = (props: ConferenceItemPropsType) => {
6566
[Attributes.TRIGERED_FROM]: 'card',
6667
[Attributes.TITLE]: item.title,
6768
[Attributes.LINK]: item.url,
68-
[Attributes.SOURCE]: 'conferences',
69+
[Attributes.SOURCE]: analyticsTag,
6970
}}>
7071
<RiCalendarEventFill className={'rowTitleIcon'} />
7172
{item.title}

src/features/conferencesCard/components/ConferencesCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getCardTagsValue } from 'src/utils/DataEnhancement'
77
import ConferenceItem from './ConferenceItem'
88

99
export function ConferencesCard({ meta, withAds }: CardPropsType) {
10-
const { userSelectedTags, listingMode } = useUserPreferences()
10+
const { userSelectedTags } = useUserPreferences()
1111

1212
const results = useGetConferences({ tags: getCardTagsValue(userSelectedTags, 'confsValues') })
1313

@@ -23,7 +23,12 @@ export function ConferencesCard({ meta, withAds }: CardPropsType) {
2323
}
2424

2525
const renderItem = (item: Conference, index: number) => (
26-
<ConferenceItem item={item} key={`cf-${index}`} index={index} listingMode={listingMode} />
26+
<ConferenceItem
27+
item={item}
28+
key={`cf-${index}`}
29+
index={index}
30+
analyticsTag={meta.analyticsTag}
31+
/>
2732
)
2833

2934
return (

src/features/devtoCard/components/ArticleItem.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import { BiCommentDetail } from 'react-icons/bi'
22
import { CardLink } from 'src/components/Elements'
33
import CardItemWithActions from 'src/components/CardItemWithActions'
44
import { Attributes } from 'src/lib/analytics'
5-
import { ArticleItemPropsType } from 'src/types'
5+
import { BaseItemPropsType, Article } from 'src/types'
6+
import { useUserPreferences } from 'src/stores/preferences'
67
import { format } from 'timeago.js'
78
import { MdAccessTime } from 'react-icons/md'
89
import { AiOutlineLike } from 'react-icons/ai'
910
import { ColoredLanguagesBadge } from 'src/components/Elements'
1011

11-
const ArticleItem = (props: ArticleItemPropsType) => {
12-
const { item, index, listingMode, selectedTag } = props
13-
12+
const ArticleItem = (props: BaseItemPropsType<Article>) => {
13+
const { item, index, selectedTag, analyticsTag } = props
14+
const { listingMode } = useUserPreferences()
15+
1416
return (
1517
<CardItemWithActions
16-
source={'devto'}
18+
source={analyticsTag}
1719
index={index}
1820
key={index}
1921
item={item}
@@ -26,7 +28,7 @@ const ArticleItem = (props: ArticleItemPropsType) => {
2628
[Attributes.POINTS]: item.reactions,
2729
[Attributes.TITLE]: item.title,
2830
[Attributes.LINK]: item.url,
29-
[Attributes.SOURCE]: 'devto',
31+
[Attributes.SOURCE]: analyticsTag,
3032
[Attributes.LANGUAGE]: selectedTag?.value,
3133
}}>
3234
{listingMode === 'compact' && (

src/features/devtoCard/components/DevtoCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SelectableCard from 'src/components/SelectableCard'
1414
const DT_MENU_LANGUAGE_ID = 'DT_MENU_LANGUAGE_ID'
1515

1616
export function DevtoCard({ withAds, meta }: CardPropsType) {
17-
const { userSelectedTags, cardsSettings, setCardSettings, listingMode } = useUserPreferences()
17+
const { userSelectedTags, cardsSettings, setCardSettings } = useUserPreferences()
1818
const [selectedTag, setSelectedTag] = useState<Tag>()
1919

2020
useEffect(() => {
@@ -52,8 +52,8 @@ export function DevtoCard({ withAds, meta }: CardPropsType) {
5252
item={item}
5353
key={`at-${index}`}
5454
index={index}
55+
analyticsTag={meta.analyticsTag}
5556
selectedTag={selectedTag}
56-
listingMode={listingMode}
5757
/>
5858
)
5959

src/features/freecodecampCard/components/ArticleItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { CardLink } from 'src/components/Elements'
22
import CardItemWithActions from 'src/components/CardItemWithActions'
33
import { Attributes } from 'src/lib/analytics'
4-
import { ArticleItemPropsType } from 'src/types'
4+
import { BaseItemPropsType, Article } from 'src/types'
55
import { format } from 'timeago.js'
66
import { MdAccessTime } from 'react-icons/md'
77
import { ColoredLanguagesBadge } from 'src/components/Elements'
88

9-
const ArticleItem = (props: ArticleItemPropsType) => {
10-
const { item, index, selectedTag } = props
9+
const ArticleItem = (props: BaseItemPropsType<Article>) => {
10+
const { item, index, selectedTag, analyticsTag } = props
1111
return (
1212
<CardItemWithActions
13-
source={'freecodecamp'}
13+
source={analyticsTag}
1414
index={index}
1515
key={index}
1616
item={item}
@@ -22,7 +22,7 @@ const ArticleItem = (props: ArticleItemPropsType) => {
2222
[Attributes.TRIGERED_FROM]: 'card',
2323
[Attributes.TITLE]: item.title,
2424
[Attributes.LINK]: item.url,
25-
[Attributes.SOURCE]: 'freecodecamp',
25+
[Attributes.SOURCE]: analyticsTag,
2626
[Attributes.LANGUAGE]: selectedTag?.value,
2727
}}>
2828
<div className="subTitle">{item.title}</div>

src/features/freecodecampCard/components/FreecodecampCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import SelectableCard from 'src/components/SelectableCard'
1414
const FCC_MENU_LANGUAGE_ID = 'FCC_MENU_LANGUAGE_ID'
1515

1616
export function FreecodecampCard({ meta, withAds }: CardPropsType) {
17-
const { userSelectedTags, cardsSettings, setCardSettings, listingMode } = useUserPreferences()
1817
const [selectedTag, setSelectedTag] = useState<Tag>()
18+
const { userSelectedTags, cardsSettings, setCardSettings } = useUserPreferences()
1919

2020
useEffect(() => {
2121
if (selectedTag) {
@@ -53,7 +53,7 @@ export function FreecodecampCard({ meta, withAds }: CardPropsType) {
5353
key={`fcc-${index}`}
5454
index={index}
5555
selectedTag={selectedTag}
56-
listingMode={listingMode}
56+
analyticsTag={meta.analyticsTag}
5757
/>
5858
)
5959

src/features/githubCard/components/GithubCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const dateRanges: DateRangeType[] = [
2525
]
2626

2727
export function GithubCard({ meta, withAds }: CardPropsType) {
28-
const { userSelectedTags, cardsSettings, setCardSettings, listingMode } = useUserPreferences()
28+
const { userSelectedTags, cardsSettings, setCardSettings } = useUserPreferences()
2929
const [selectedTag, setSelectedTag] = useState<Tag>()
3030
const [selectedDateRange, setSelectedDateRange] = useState<DateRangeType>(dateRanges[0])
3131

@@ -80,7 +80,7 @@ export function GithubCard({ meta, withAds }: CardPropsType) {
8080
key={`rp-${index}`}
8181
index={index}
8282
selectedTag={selectedTag}
83-
listingMode={listingMode}
83+
analyticsTag={meta.analyticsTag}
8484
/>
8585
)
8686

src/features/githubCard/components/RepoItem.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { CardLink } from 'src/components/Elements'
22
import CardItemWithActions from 'src/components/CardItemWithActions'
33
import { Attributes } from 'src/lib/analytics'
4-
import { RepoItemPropsType } from 'src/types'
54
import { ColoredLanguagesBadge } from 'src/components/Elements'
65
import { VscRepo, VscRepoForked, VscStarFull } from 'react-icons/vsc'
7-
8-
const sourceName = 'github'
6+
import { BaseItemPropsType, Repository } from 'src/types'
7+
import { useUserPreferences } from 'src/stores/preferences'
98

109
function numberWithCommas(x: number | string) {
1110
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
1211
}
1312

14-
const RepoItem = (props: RepoItemPropsType) => {
15-
const { item, index, listingMode, selectedTag } = props
13+
const RepoItem = ({ item, index, selectedTag, analyticsTag }: BaseItemPropsType<Repository>) => {
14+
const { listingMode } = useUserPreferences()
1615

1716
return (
1817
<CardItemWithActions
19-
source={sourceName}
18+
source={analyticsTag}
2019
key={index}
2120
index={index}
2221
item={item}
@@ -30,7 +29,7 @@ const RepoItem = (props: RepoItemPropsType) => {
3029
[Attributes.TRIGERED_FROM]: 'card',
3130
[Attributes.TITLE]: item.title,
3231
[Attributes.LINK]: item.url,
33-
[Attributes.SOURCE]: sourceName,
32+
[Attributes.SOURCE]: analyticsTag,
3433
[Attributes.LANGUAGE]: selectedTag?.value,
3534
}}>
3635
<VscRepo className={'rowTitleIcon'} />

src/features/hackernewsCard/components/ArticleItem.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import { CardLink } from 'src/components/Elements'
77
import CardItemWithActions from '../../../components/CardItemWithActions'
88
import ClickableItem from '../../../components/ClickableItem'
99
import { Attributes } from 'src/lib/analytics'
10-
import { ArticleItemPropsType } from 'src/types'
10+
import { BaseItemPropsType, Article } from 'src/types'
11+
import { useUserPreferences } from 'src/stores/preferences'
1112

12-
const ArticleItem = (props: ArticleItemPropsType) => {
13-
const { item, index, listingMode } = props
13+
const ArticleItem = (props: BaseItemPropsType<Article>) => {
14+
const { item, index, analyticsTag } = props
15+
const { listingMode } = useUserPreferences()
1416

1517
return (
1618
<CardItemWithActions
17-
source={'hackernews'}
19+
source={analyticsTag}
1820
index={index}
1921
item={item}
2022
key={index}
@@ -28,7 +30,7 @@ const ArticleItem = (props: ArticleItemPropsType) => {
2830
[Attributes.TRIGERED_FROM]: 'card',
2931
[Attributes.TITLE]: item.title,
3032
[Attributes.LINK]: item.url,
31-
[Attributes.SOURCE]: 'hackernews',
33+
[Attributes.SOURCE]: analyticsTag,
3234
}}>
3335
{listingMode === 'compact' && (
3436
<span className="counterWrapper">
@@ -56,7 +58,7 @@ const ArticleItem = (props: ArticleItemPropsType) => {
5658
[Attributes.TRIGERED_FROM]: 'card',
5759
[Attributes.TITLE]: `${item.title} comments`,
5860
[Attributes.LINK]: `https://news.ycombinator.com/item?id=${item.id}`,
59-
[Attributes.SOURCE]: 'hackernews',
61+
[Attributes.SOURCE]: analyticsTag,
6062
}}>
6163
<BiCommentDetail className="rowItemIcon" /> {item.comments} comments
6264
</ClickableItem>

src/features/hackernewsCard/components/HackernewsCard.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { Card } from 'src/components/Elements'
22
import { ListComponent } from 'src/components/List'
3-
import { useUserPreferences } from 'src/stores/preferences'
43
import { useGetArticles } from '../api/getArticles'
54
import { Article, CardPropsType } from 'src/types'
65
import ArticleItem from './ArticleItem'
76

87
export function HackernewsCard({ meta, withAds }: CardPropsType) {
98
const { data: articles = [], isLoading, error } = useGetArticles()
10-
const { listingMode } = useUserPreferences()
119

1210
const renderItem = (item: Article, index: number) => (
13-
<ArticleItem item={item} key={`hn-${index}`} index={index} listingMode={listingMode} />
11+
<ArticleItem item={item} key={`hn-${index}`} index={index} analyticsTag={meta.analyticsTag} />
1412
)
1513

1614
return (

0 commit comments

Comments
 (0)