Skip to content

Commit a37b1d3

Browse files
committed
fix: add Hackernews and Lobsters sources to FeedItemSource and update styles for source display
1 parent adc4681 commit a37b1d3

3 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/features/feed/components/FeedItemSource.tsx

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { memo, useState } from 'react'
12
import { FaDev, FaMediumM, FaReddit } from 'react-icons/fa'
23
import { GoDotFill } from 'react-icons/go'
3-
import { SiGithub, SiProducthunt } from 'react-icons/si'
4+
import { SiGithub, SiProducthunt, SiYcombinator } from 'react-icons/si'
45
import HashNodeIcon from 'src/assets/icon_hashnode.png'
5-
const FeedItemKV: {
6-
[key: string]: React.ReactNode
7-
} = {
6+
import LobstersIcon from 'src/assets/icon_lobsters.png'
7+
8+
const SOURCE_MAP: Record<string, React.ReactNode> = {
89
producthunt: (
910
<>
1011
<SiProducthunt color="#D65736" /> Product hunt
@@ -35,13 +36,43 @@ const FeedItemKV: {
3536
<img alt="hn" className="feedItemSource" src={HashNodeIcon} /> Hashnode
3637
</>
3738
),
39+
hackernews: (
40+
<>
41+
<SiYcombinator color="#FB6720" /> Hackernews
42+
</>
43+
),
44+
lobsters: (
45+
<>
46+
<img alt="lobsters" className="feedItemSource" src={LobstersIcon} /> Lobsters
47+
</>
48+
),
3849
}
39-
export const FeedItemSource = ({ source }: { source: string }) => {
40-
return (
41-
FeedItemKV[source] || (
50+
export const FeedItemSource = memo(({ source }: { source: string }) => {
51+
const [fallback, setFallback] = useState(false)
52+
53+
if (SOURCE_MAP[source]) {
54+
return SOURCE_MAP[source]
55+
}
56+
57+
if (!fallback && source.includes('.')) {
58+
return (
4259
<>
43-
<GoDotFill className="rowItemIcon" /> {source}
60+
<img
61+
src={`https://icons.duckduckgo.com/ip3/${source}.ico`}
62+
alt={source}
63+
className="feedItemSourceFallback"
64+
onError={() => {
65+
setFallback(true)
66+
}}
67+
/>{' '}
68+
<span className="sourceName">{source}</span>
4469
</>
4570
)
71+
}
72+
73+
return (
74+
<>
75+
<GoDotFill className="rowItemIcon" /> <span className="sourceName">{source}</span>
76+
</>
4677
)
47-
}
78+
})

src/features/feed/components/feed.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,16 @@
130130
margin: 0;
131131
padding: 0;
132132
}
133+
134+
.sourceName {
135+
text-transform: none;
136+
137+
&::first-letter {
138+
text-transform: capitalize;
139+
}
140+
}
141+
142+
.feedItemSourceFallback {
143+
width: 12px;
144+
height: 12px;
145+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export const ArticleFeedItem = (props: BaseItemPropsType<ArticleFeedItemData>) =
2020
<FeedItemHeader {...item} />
2121
{listingMode === 'compact' && (
2222
<div className="rowDetails">
23-
<span className="rowItem capitalize verticalAligned">
23+
<span className="rowItem feedSource verticalAligned">
2424
<FeedItemSource source={item.source} />
2525
</span>
2626
</div>
2727
)}
2828
{listingMode === 'normal' && (
2929
<div className="rowDetails">
30-
<span className="rowItem capitalize verticalAligned">
30+
<span className="rowItem feedSource verticalAligned">
3131
<FeedItemSource source={item.source} />
3232
</span>
3333
<span className="rowItem" title={new Date(item.date).toUTCString()}>

0 commit comments

Comments
 (0)