|
| 1 | +import { memo, useState } from 'react' |
1 | 2 | import { FaDev, FaMediumM, FaReddit } from 'react-icons/fa' |
2 | 3 | import { GoDotFill } from 'react-icons/go' |
3 | | -import { SiGithub, SiProducthunt } from 'react-icons/si' |
| 4 | +import { SiGithub, SiProducthunt, SiYcombinator } from 'react-icons/si' |
4 | 5 | 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> = { |
8 | 9 | producthunt: ( |
9 | 10 | <> |
10 | 11 | <SiProducthunt color="#D65736" /> Product hunt |
@@ -35,13 +36,43 @@ const FeedItemKV: { |
35 | 36 | <img alt="hn" className="feedItemSource" src={HashNodeIcon} /> Hashnode |
36 | 37 | </> |
37 | 38 | ), |
| 39 | + hackernews: ( |
| 40 | + <> |
| 41 | + <SiYcombinator color="#FB6720" /> Hackernews |
| 42 | + </> |
| 43 | + ), |
| 44 | + lobsters: ( |
| 45 | + <> |
| 46 | + <img alt="lobsters" className="feedItemSource" src={LobstersIcon} /> Lobsters |
| 47 | + </> |
| 48 | + ), |
38 | 49 | } |
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 ( |
42 | 59 | <> |
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> |
44 | 69 | </> |
45 | 70 | ) |
| 71 | + } |
| 72 | + |
| 73 | + return ( |
| 74 | + <> |
| 75 | + <GoDotFill className="rowItemIcon" /> <span className="sourceName">{source}</span> |
| 76 | + </> |
46 | 77 | ) |
47 | | -} |
| 78 | +}) |
0 commit comments