Skip to content

Commit c260fb6

Browse files
committed
feat: add FeedItemSource component for consistent feed item source rendering
1 parent c3fb9c5 commit c260fb6

5 files changed

Lines changed: 55 additions & 7 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { FaDev, FaMediumM, FaReddit } from 'react-icons/fa'
2+
import { GoDotFill } from 'react-icons/go'
3+
import { SiProducthunt } from 'react-icons/si'
4+
import HashNodeIcon from 'src/assets/icon_hashnode.png'
5+
const FeedItemKV: {
6+
[key: string]: React.ReactNode
7+
} = {
8+
producthunt: (
9+
<>
10+
<SiProducthunt color="#D65736" /> Product hunt
11+
</>
12+
),
13+
reddit: (
14+
<>
15+
<FaReddit color="#FF4500" /> Reddit
16+
</>
17+
),
18+
medium: (
19+
<>
20+
<FaMediumM className="blockHeaderWhite" /> Medium
21+
</>
22+
),
23+
devto: (
24+
<>
25+
<FaDev className="blockHeaderWhite" /> Dev.to
26+
</>
27+
),
28+
hashnode: (
29+
<>
30+
<img alt="hn" className="feedItemSource" src={HashNodeIcon} /> Hashnode
31+
</>
32+
),
33+
}
34+
export const FeedItemSource = ({ source }: { source: string }) => {
35+
return (
36+
FeedItemKV[source] || (
37+
<>
38+
<GoDotFill className="rowItemIcon" /> {source}
39+
</>
40+
)
41+
)
42+
}

src/features/feed/components/feed.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
border: 1px solid var(--card-border-color);
2121
border-radius: 10px;
2222
}
23+
.feedItemSource {
24+
width: 12px;
25+
height: 12px;
26+
}
2327

2428
.loading {
2529
display: flex;

src/features/feed/components/feedItems/ArticleFeedItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { GoDotFill } from 'react-icons/go'
21
import { MdAccessTime } from 'react-icons/md'
32
import { CardItemWithActions } from 'src/components/Elements'
43
import { useUserPreferences } from 'src/stores/preferences'
54
import { ArticleFeedItemData, BaseItemPropsType } from 'src/types'
65
import { format } from 'timeago.js'
76
import { FeedItemHeader } from '../FeedItemHeader'
7+
import { FeedItemSource } from '../FeedItemSource'
88

99
export const ArticleFeedItem = (props: BaseItemPropsType<ArticleFeedItemData>) => {
1010
const { item, index, analyticsTag, className } = props
@@ -22,15 +22,15 @@ export const ArticleFeedItem = (props: BaseItemPropsType<ArticleFeedItemData>) =
2222
<FeedItemHeader {...item} />
2323
{listingMode === 'compact' && (
2424
<div className="rowDetails">
25-
<span className="rowItem capitalize">
26-
<GoDotFill className="rowItemIcon" /> {item.source}
25+
<span className="rowItem capitalize verticalAligned">
26+
<FeedItemSource source={item.source} />
2727
</span>
2828
</div>
2929
)}
3030
{listingMode === 'normal' && (
3131
<div className="rowDetails">
32-
<span className="rowItem capitalize">
33-
<GoDotFill className="rowItemIcon" /> {item.source}
32+
<span className="rowItem capitalize verticalAligned">
33+
<FeedItemSource source={item.source} />
3434
</span>
3535
<span className="rowItem" title={new Date(item.date).toUTCString()}>
3636
<MdAccessTime className="rowItemIcon" /> {format(new Date(item.date))}

src/features/feed/components/feedItems/ProductFeedItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CardItemWithActions } from 'src/components/Elements'
44
import { useUserPreferences } from 'src/stores/preferences'
55
import { BaseItemPropsType, ProductHuntFeedItemData } from 'src/types'
66
import { FeedItemHeader } from '../FeedItemHeader'
7+
import { FeedItemSource } from '../FeedItemSource'
78

89
export const ProductFeedItem = (props: BaseItemPropsType<ProductHuntFeedItemData>) => {
910
const { item, index, analyticsTag, className } = props
@@ -32,7 +33,7 @@ export const ProductFeedItem = (props: BaseItemPropsType<ProductHuntFeedItemData
3233
{listingMode === 'normal' && (
3334
<div className="rowDetails">
3435
<span className="rowItem verticalAligned">
35-
<SiProducthunt color="#D65736" /> Product Hunt
36+
<FeedItemSource source={'producthunt'} />
3637
</span>
3738
<span className="rowItem verticalAligned">
3839
<VscTriangleUp className="rowItemIcon" /> {item.votes_count || 0} upvotes

src/features/feed/components/feedItems/RepoFeedItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CardItemWithActions, ColoredLanguagesBadge } from 'src/components/Eleme
44
import { useUserPreferences } from 'src/stores/preferences'
55
import { BaseItemPropsType, GithubFeedItemData } from 'src/types'
66
import { FeedItemHeader } from '../FeedItemHeader'
7+
import { FeedItemSource } from '../FeedItemSource'
78

89
function numberWithCommas(x: number | string) {
910
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
@@ -47,7 +48,7 @@ export const RepoFeedItem = (props: BaseItemPropsType<GithubFeedItemData>) => {
4748
{listingMode === 'normal' && (
4849
<div className="rowDetails">
4950
<span className="rowItem verticalAligned">
50-
<SiGithub className="blockHeaderWhite" /> Github
51+
<FeedItemSource source={'github'} />
5152
</span>
5253
{item.stars && (
5354
<span className="rowItem">

0 commit comments

Comments
 (0)