2022-05-28 09:02:04 -07:00
import React , { useEffect } from 'react' ;
2022-04-13 07:07:50 -07:00
import { FormattedMessage } from 'react-intl' ;
import { useParams } from 'react-router-dom' ;
import { fetchList } from 'soapbox/actions/lists' ;
import { openModal } from 'soapbox/actions/modals' ;
import { connectListStream } from 'soapbox/actions/streaming' ;
import { expandListTimeline } from 'soapbox/actions/timelines' ;
2022-11-15 08:00:49 -08:00
import MissingIndicator from 'soapbox/components/missing-indicator' ;
2022-11-30 09:19:16 -08:00
import { Column , Button , Spinner } from 'soapbox/components/ui' ;
2022-06-18 11:58:42 -07:00
import { useAppDispatch , useAppSelector } from 'soapbox/hooks' ;
2022-04-13 07:07:50 -07:00
2022-06-03 10:31:23 -07:00
import Timeline from '../ui/components/timeline' ;
2022-04-13 07:07:50 -07:00
const ListTimeline : React.FC = ( ) = > {
2022-06-18 11:58:42 -07:00
const dispatch = useAppDispatch ( ) ;
2022-04-13 07:07:50 -07:00
const { id } = useParams < { id : string } > ( ) ;
const list = useAppSelector ( ( state ) = > state . lists . get ( id ) ) ;
useEffect ( ( ) = > {
2022-06-18 11:58:42 -07:00
dispatch ( fetchList ( id ) ) ;
dispatch ( expandListTimeline ( id ) ) ;
const disconnect = dispatch ( connectListStream ( id ) ) ;
2022-04-13 07:07:50 -07:00
return ( ) = > {
disconnect ( ) ;
} ;
} , [ id ] ) ;
const handleLoadMore = ( maxId : string ) = > {
dispatch ( expandListTimeline ( id , { maxId } ) ) ;
} ;
const handleEditClick = ( ) = > {
dispatch ( openModal ( 'LIST_EDITOR' , { listId : id } ) ) ;
} ;
2022-06-02 11:51:09 -07:00
const title = list ? list.title : id ;
2022-04-13 07:07:50 -07:00
if ( typeof list === 'undefined' ) {
return (
< Column >
< div >
< Spinner / >
< / div >
< / Column >
) ;
} else if ( list === false ) {
return (
< MissingIndicator / >
) ;
}
const emptyMessage = (
< div >
< FormattedMessage id = 'empty_column.list' defaultMessage = 'There is nothing in this list yet. When members of this list create new posts, they will appear here.' / >
< br / > < br / >
< Button onClick = { handleEditClick } > < FormattedMessage id = 'list.click_to_add' defaultMessage = 'Click here to add people' / > < / Button >
< / div >
) ;
return (
2022-11-30 09:19:16 -08:00
< Column label = { title } transparent >
2022-06-03 10:31:23 -07:00
< Timeline
2022-04-13 07:07:50 -07:00
scrollKey = 'list_timeline'
timelineId = { ` list: ${ id } ` }
onLoadMore = { handleLoadMore }
emptyMessage = { emptyMessage }
divideType = 'space'
/ >
< / Column >
) ;
} ;
export default ListTimeline ;