File tree Expand file tree Collapse file tree
features/feed/components/feedItems Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { GoDotFill } from 'react-icons/go'
2+ import { MdAccessTime } from 'react-icons/md'
3+ import { CardItemWithActions } from 'src/components/Elements'
4+ import { useUserPreferences } from 'src/stores/preferences'
5+ import { ArticleFeedItemData , BaseItemPropsType } from 'src/types'
6+ import { format } from 'timeago.js'
7+ import { FeedItemHeader } from '../FeedItemHeader'
8+
9+ export const ArticleFeedItem = ( props : BaseItemPropsType < ArticleFeedItemData > ) => {
10+ const { item, index, analyticsTag } = props
11+ const { listingMode } = useUserPreferences ( )
12+
13+ return (
14+ < CardItemWithActions
15+ source = { analyticsTag }
16+ index = { index }
17+ item = { item }
18+ key = { index }
19+ cardItem = {
20+ < >
21+ < FeedItemHeader item = { item } />
22+ { listingMode === 'compact' && (
23+ < div className = "rowDetails" >
24+ < span className = "rowItem capitalize" >
25+ < GoDotFill className = "rowItemIcon" /> { item . source }
26+ </ span >
27+ </ div >
28+ ) }
29+ { listingMode === 'normal' && (
30+ < div className = "rowDetails" >
31+ < span className = "rowItem capitalize" >
32+ < GoDotFill className = "rowItemIcon" /> { item . source }
33+ </ span >
34+ < span className = "rowItem" title = { new Date ( item . date ) . toUTCString ( ) } >
35+ < MdAccessTime className = "rowItemIcon" /> { format ( new Date ( item . date ) ) }
36+ </ span >
37+ </ div >
38+ ) }
39+ </ >
40+ }
41+ />
42+ )
43+ }
Original file line number Diff line number Diff line change 1+ import { BaseItemPropsType , FeedItemData } from 'src/types'
2+ import { ArticleFeedItem } from './ArticleFeedItem'
3+ import { ProductFeedItem } from './ProductFeedItem'
4+ import { RepoFeedItem } from './RepoFeedItem'
5+
6+ export const FeedItem = ( props : BaseItemPropsType < FeedItemData > ) => {
7+ const { item, index, analyticsTag } = props
8+
9+ if ( item . type === 'repo' ) {
10+ return < RepoFeedItem item = { item } index = { index } analyticsTag = { analyticsTag } />
11+ }
12+
13+ if ( item . type === 'producthunt' ) {
14+ return < ProductFeedItem item = { item } index = { index } analyticsTag = { analyticsTag } />
15+ }
16+
17+ if ( item . type === 'post' ) {
18+ return < ArticleFeedItem item = { item } index = { index } analyticsTag = { analyticsTag } />
19+ }
20+
21+ return null
22+ }
Original file line number Diff line number Diff line change 1+ import { GoDotFill } from 'react-icons/go'
2+ import { CardItemWithActions } from 'src/components/Elements'
3+ import { useUserPreferences } from 'src/stores/preferences'
4+ import { BaseItemPropsType , ProductHuntFeedItemData } from 'src/types'
5+ import { FeedItemHeader } from '../FeedItemHeader'
6+
7+ export const ProductFeedItem = ( props : BaseItemPropsType < ProductHuntFeedItemData > ) => {
8+ const { item, index, analyticsTag } = props
9+ const { listingMode } = useUserPreferences ( )
10+
11+ return (
12+ < CardItemWithActions
13+ source = { analyticsTag }
14+ index = { index }
15+ item = { item }
16+ key = { index }
17+ cardItem = {
18+ < >
19+ < FeedItemHeader item = { item } />
20+ < div className = "rowDetails" >
21+ < span className = "rowItem" > { item . tagline } </ span >
22+ </ div >
23+ { listingMode === 'compact' && (
24+ < div className = "rowDetails" >
25+ < span className = "rowItem capitalize" >
26+ < GoDotFill className = "rowItemIcon" /> Product Hunt
27+ </ span >
28+ </ div >
29+ ) }
30+ { listingMode === 'normal' && (
31+ < div className = "rowDetails" >
32+ < span className = "rowItem capitalize" >
33+ < GoDotFill className = "rowItemIcon" /> Product Hunt
34+ </ span >
35+ </ div >
36+ ) }
37+ </ >
38+ }
39+ />
40+ )
41+ }
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ import { SiGithub } from 'react-icons/si'
22import { VscRepoForked , VscStarFull } from 'react-icons/vsc'
33import { CardItemWithActions , ColoredLanguagesBadge } from 'src/components/Elements'
44import { useUserPreferences } from 'src/stores/preferences'
5- import { BaseItemPropsType , FeedItem as FeedItemType } from 'src/types'
5+ import { BaseItemPropsType , GithubFeedItemData } from 'src/types'
66import { FeedItemHeader } from '../FeedItemHeader'
77
88function numberWithCommas ( x : number | string ) {
99 return x . toString ( ) . replace ( / \B (? = ( \d { 3 } ) + (? ! \d ) ) / g, ',' )
1010}
1111
12- export const RepoFeedItem = ( props : BaseItemPropsType < FeedItemType > ) => {
12+ export const RepoFeedItem = ( props : BaseItemPropsType < GithubFeedItemData > ) => {
1313 const { item, index, analyticsTag } = props
1414 const { listingMode } = useUserPreferences ( )
1515
Original file line number Diff line number Diff line change @@ -50,17 +50,37 @@ export type Article = BaseEntry & {
5050 flair_text_color ?: string
5151}
5252
53- export type FeedItem = BaseEntry & {
53+ export type FeedItem = {
54+ title : string
55+ id : string
56+ url : string
5457 date : Date
5558 image : string
56- type : 'post' | 'github'
59+ tags : Array < string >
60+ }
61+
62+ export type ArticleFeedItemData = FeedItem & {
63+ type : 'post'
5764 source : string
58- stars ?: number
59- forks ?: number
65+ }
66+
67+ export type ProductHuntFeedItemData = FeedItem & {
68+ type : 'producthunt'
69+ tagline : string
70+ votes : number
71+ comments : number
72+ }
73+
74+ export type GithubFeedItemData = FeedItem & {
75+ type : 'repo'
76+ stars : number
77+ forks : number
78+ programmingLanguage : string
6079 description ?: string
61- tags : Array < string >
6280}
6381
82+ export type FeedItemData = ArticleFeedItemData | GithubFeedItemData | ProductHuntFeedItemData
83+
6484export type Repository = BaseEntry & {
6585 programmingLanguage : string
6686 stars : number
You can’t perform that action at this time.
0 commit comments