1- import { CardLink , CardItemWithActions } from 'src/components/Elements'
2- import { Attributes } from 'src/lib/analytics'
3- import { BaseItemPropsType , Conference } from 'src/types'
4- import { MdAccessTime } from 'react-icons/md'
5- import { ColoredLanguagesBadge } from 'src/components/Elements'
61import { flag } from 'country-emoji'
2+ import { useMemo } from 'react'
73import { IoIosPin } from 'react-icons/io'
8- import { RiCalendarEventFill } from 'react-icons/ri'
4+ import { MdAccessTime } from 'react-icons/md'
5+ import { CardItemWithActions , CardLink , ColoredLanguagesBadge } from 'src/components/Elements'
6+ import { Attributes } from 'src/lib/analytics'
97import { useUserPreferences } from 'src/stores/preferences'
8+ import { BaseItemPropsType , Conference } from 'src/types'
109
1110const ConferencesItem = ( { item, index, analyticsTag } : BaseItemPropsType < Conference > ) => {
1211 const { listingMode } = useUserPreferences ( )
1312
14- const ConferenceLocation = ( ) => {
13+ const conferenceLocation = useMemo ( ( ) => {
1514 if ( item . online ) {
16- return '🌐 Online'
15+ return {
16+ icon : '🌐' ,
17+ label : 'Online' ,
18+ }
1719 }
1820 if ( item . country ) {
19- return `${ flag ( item . country . replace ( / [ ^ a - z A - Z ] / g, '' ) ) } ${ item . city } `
21+ return {
22+ icon : flag ( item . country . replace ( / [ ^ a - z A - Z ] / g, '' ) ) || '🏳️' ,
23+ label : item . city ,
24+ }
2025 }
21- }
26+ return null
27+ } , [ item . online , item . country , item . city ] )
2228
23- const ConferenceDate = ( ) => {
29+ const conferenceDate = useMemo ( ( ) => {
2430 if ( ! item . start_date ) {
2531 return ''
2632 }
@@ -50,7 +56,17 @@ const ConferencesItem = ({ item, index, analyticsTag }: BaseItemPropsType<Confer
5056 endValue = `${ monthNames [ endDate . getMonth ( ) ] } ${ endValue } `
5157 }
5258 return `${ value } - ${ endValue } `
53- }
59+ } , [ item . start_date , item . end_date ] )
60+
61+ const differenceInDays = useMemo ( ( ) => {
62+ if ( ! item . start_date ) {
63+ return 0
64+ }
65+ const startDate = new Date ( item . start_date )
66+ const currentDate = new Date ( )
67+ const diffTime = startDate . getTime ( ) - currentDate . getTime ( )
68+ return Math . ceil ( diffTime / ( 1000 * 60 * 60 * 24 ) )
69+ } , [ item . start_date ] )
5470 return (
5571 < CardItemWithActions
5672 source = { analyticsTag }
@@ -67,17 +83,22 @@ const ConferencesItem = ({ item, index, analyticsTag }: BaseItemPropsType<Confer
6783 [ Attributes . LINK ] : item . url ,
6884 [ Attributes . SOURCE ] : analyticsTag ,
6985 } } >
70- < RiCalendarEventFill className = { ' rowTitleIcon' } / >
86+ < span className = " rowTitleIcon" > { conferenceLocation ?. icon } </ span >
7187 { item . title }
7288 </ CardLink >
7389 { listingMode === 'normal' ? (
7490 < >
7591 < div className = "rowDescription" >
7692 < span className = "rowItem" >
77- < IoIosPin className = "rowItemIcon" /> { ConferenceLocation ( ) }
93+ < IoIosPin className = "rowItemIcon" /> { conferenceLocation ?. label }
7894 </ span >
7995 < span className = "rowItem" >
80- < MdAccessTime className = "rowItemIcon" /> { ConferenceDate ( ) }
96+ < MdAccessTime className = "rowItemIcon" /> { ` ` }
97+ { differenceInDays > 0
98+ ? `In ${ differenceInDays } days, ${ conferenceDate } `
99+ : differenceInDays === 0
100+ ? `Ongoing, ${ conferenceDate } `
101+ : `${ conferenceDate } (ended)` }
81102 </ span >
82103 </ div >
83104 < div className = "rowDetails" >
@@ -87,7 +108,7 @@ const ConferencesItem = ({ item, index, analyticsTag }: BaseItemPropsType<Confer
87108 ) : (
88109 < div className = "rowDescription" >
89110 < span className = "rowItem" >
90- < MdAccessTime className = "rowItemIcon" /> { ConferenceDate ( ) }
111+ < MdAccessTime className = "rowItemIcon" /> { conferenceDate }
91112 </ span >
92113 </ div >
93114 ) }
0 commit comments