import React , { useEffect , useState } from 'react' ; import LoadingIndicator from 'src/components/LoadingIndicator/LoadingIndicator' ; import { Offer } from 'src/models/offers' ; import { RequestWithOffersAndTimeline } from 'src/models/requests/RequestWithOffersAndTimeline' ; const RequestList = ( { requests , loading , handleRequest , isCavAndOpenRequest , isPinAndOpenRequest , RequestItem , cavDeclinedOffersGiven , hideUserPics , toCloseRequest , } ) : React . ReactElement => { const [ requestList , setRequestList ] = useState < React . ReactElement < any > [ ] > ( [ ] ) ; const [ requestsRendered , setRequestsRendered ] = useState < Record < string , boolean > > ( { } ) ; useEffect ( ( ) => { if ( requests ) { const internalRequestList = [ ] ; const internalRequestsRendered = { } ; for ( const id in requests ) { if ( id && requests [ id ] && ! requestsRendered [ id ] ) { internalRequestsRendered [ id ] = true ; internalRequestList . push ( < RequestItem key = { id } request = { requests [ id ] . getRequest ( ) } handleRequest = { ( action ? ) => handleRequest && handleRequest ( id , action ) } isCavAndOpenRequest = { isCavAndOpenRequest } isPinAndOpenRequest = { isPinAndOpenRequest } offers = { requests [ id ] . offers } toCloseRequest = { ( action ? ) => toCloseRequest && toCloseRequest ( id , action ) } />); } } if ( internalRequestList . length ) { setRequestsRendered ( internalRequestsRendered ) ; setRequestList ( internalRequestList ) ; } } } , [ requests , handleRequest , isCavAndOpenRequest , isPinAndOpenRequest , cavDeclinedOffersGiven , hideUserPics , requestsRendered , toCloseRequest , setRequestList , ] ) ; if ( loading ) { return < LoadingIndicator />; } return < div style = { { marginBottom : '64px' } } > { requestList } < /div>; } ; interface RequestListProps { requests ? : Record < string , RequestWithOffersAndTimeline > ; loading : boolean ; handleRequest ? : Function ; isCavAndOpenRequest ? : boolean ; isPinAndOpenRequest ? : boolean ; RequestItem : React . FC < any > ; pendingOffersGiven ? : Record < string , Offer [ ] > ; cavDeclinedOffersGiven ? : Record < string , Offer [ ] > ; hideUserPics ? : boolean ; toCloseRequest ? : Function ; } export default RequestList ;