import React , { ReactElement } from 'react' ; import { DateFormatter , EventModel } from 'api-client' ; import EventPlaceholder1 from '../assets/EventPlaceholder1.jpg' ; import EventPlaceholder2 from '../assets/EventPlaceholder2.jpg' ; import EventPlaceholder3 from '../assets/EventPlaceholder3.jpg' ; import { textTruncator } from '../utils/stringUtils' ; import ListItem from './ListItem' ; export const NUM_OF_CHARS_ALLOWED = 110 ; type PropsType = { event : EventModel ; formatter : DateFormatter ; } ; returns { * } const getEventPlaceholder = ( path ) : string => { const pseudoId = path . split ( '' ) . reduce ( ( acc , char ) => acc + char . charCodeAt ( 0 ) , 0 ) ; const placeholders = [ EventPlaceholder1 , EventPlaceholder2 , EventPlaceholder3 ] ; return placeholders [ pseudoId % placeholders . length ] ! ; } ; const EventListItem = ( { event , formatter } ) : ReactElement => ( < ListItem thumbnail = { event . thumbnail || getEventPlaceholder ( event . path ) } title = { event . title } path = { event . path } > < div > < div > { event . date . toFormattedString ( formatter ) } < /div> { event . location . location && < div > { event . location . location } < /div>} < /div> < div > { textTruncator ( event . excerpt , NUM_OF_CHARS_ALLOWED ) } < /div> < /ListItem>); export default EventListItem ;