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' ;
import MissingIndicator from 'soapbox/components/missing_indicator' ;
import { Button , Spinner } from 'soapbox/components/ui' ;
import Column from 'soapbox/features/ui/components/column' ;
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 messages = defineMessages({
// deleteHeading: { id: 'confirmations.delete_list.heading', defaultMessage: 'Delete list' },
// deleteMessage: { id: 'confirmations.delete_list.message', defaultMessage: 'Are you sure you want to permanently delete this list?' },
// deleteConfirm: { id: 'confirmations.delete_list.confirm', defaultMessage: 'Delete' },
// });
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 intl = useIntl();
// const history = useHistory();
const list = useAppSelector ( ( state ) = > state . lists . get ( id ) ) ;
2022-06-23 15:33:23 -07:00
// const hasUnread = useAppSelector((state) => state.timelines.get(`list:${props.params.id}`)?.unread > 0);
2022-04-13 07:07:50 -07:00
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 } ) ) ;
} ;
// const handleDeleteClick = () => {
// dispatch(openModal('CONFIRM', {
2022-07-09 09:20:02 -07:00
// icon: require('@tabler/icons/trash.svg'),
2022-04-13 07:07:50 -07:00
// heading: intl.formatMessage(messages.deleteHeading),
// message: intl.formatMessage(messages.deleteMessage),
// confirm: intl.formatMessage(messages.deleteConfirm),
// onConfirm: () => {
// dispatch(deleteList(id));
// history.push('/lists');
// },
// }));
// };
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-07-15 15:03:21 -07:00
< Column label = { title } heading = { title } transparent withHeader = { false } >
2022-04-13 07:07:50 -07:00
{ / * < H o m e C o l u m n H e a d e r a c t i v e I t e m = ' l i s t s ' a c t i v e S u b I t e m = { i d } a c t i v e = { h a s U n r e a d } >
< div className = 'column-header__links' >
< button className = 'text-btn column-header__setting-btn' tabIndex = '0' onClick = { handleEditClick } >
< Icon id = 'pencil' / > < FormattedMessage id = 'lists.edit' defaultMessage = 'Edit list' / >
< / button >
< button className = 'text-btn column-header__setting-btn' tabIndex = '0' onClick = { handleDeleteClick } >
< Icon id = 'trash' / > < FormattedMessage id = 'lists.delete' defaultMessage = 'Delete list' / >
< / button >
< hr / >
< Link to = '/lists' className = 'text-btn column-header__setting-btn column-header__setting-btn--link' >
< FormattedMessage id = 'lists.view_all' defaultMessage = 'View all lists' / >
< Icon id = 'arrow-right' / >
< / Link >
< / div >
< / HomeColumnHeader > * / }
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 ;