2022-06-16 12:32:17 -07:00
import debounce from 'lodash/debounce' ;
2022-05-28 09:02:04 -07:00
import React , { useEffect } from 'react' ;
2022-05-23 12:14:42 -07:00
import { defineMessages , FormattedMessage , useIntl } from 'react-intl' ;
2022-11-16 05:32:32 -08:00
import { fetchScheduledStatuses , expandScheduledStatuses } from 'soapbox/actions/scheduled-statuses' ;
2022-11-15 08:00:49 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
2022-05-23 12:14:42 -07:00
import { useAppSelector , useAppDispatch } from 'soapbox/hooks' ;
import Column from '../ui/components/column' ;
2022-11-15 11:00:40 -08:00
import ScheduledStatus from './components/scheduled-status' ;
2022-05-23 12:14:42 -07:00
const messages = defineMessages ( {
heading : { id : 'column.scheduled_statuses' , defaultMessage : 'Scheduled Posts' } ,
} ) ;
const handleLoadMore = debounce ( ( dispatch ) = > {
dispatch ( expandScheduledStatuses ( ) ) ;
} , 300 , { leading : true } ) ;
const ScheduledStatuses = ( ) = > {
const intl = useIntl ( ) ;
const dispatch = useAppDispatch ( ) ;
2022-06-05 07:17:26 -07:00
const statusIds = useAppSelector ( ( state ) = > state . status_lists . get ( 'scheduled_statuses' ) ! . items ) ;
const isLoading = useAppSelector ( ( state ) = > state . status_lists . get ( 'scheduled_statuses' ) ! . isLoading ) ;
const hasMore = useAppSelector ( ( state ) = > ! ! state . status_lists . get ( 'scheduled_statuses' ) ! . next ) ;
2022-05-23 12:14:42 -07:00
useEffect ( ( ) = > {
dispatch ( fetchScheduledStatuses ( ) ) ;
} , [ ] ) ;
const emptyMessage = < FormattedMessage id = 'empty_column.scheduled_statuses' defaultMessage = "You don't have any scheduled statuses yet. When you add one, it will show up here." / > ;
return (
< Column icon = 'calendar' label = { intl . formatMessage ( messages . heading ) } >
< ScrollableList
scrollKey = 'scheduled_statuses'
hasMore = { hasMore }
2022-06-05 07:17:26 -07:00
isLoading = { typeof isLoading === 'boolean' ? isLoading : true }
2022-05-23 12:14:42 -07:00
onLoadMore = { ( ) = > handleLoadMore ( dispatch ) }
emptyMessage = { emptyMessage }
>
{ statusIds . map ( ( id : string ) = > < ScheduledStatus key = { id } statusId = { id } / > ) }
< / ScrollableList >
< / Column >
) ;
} ;
2022-06-16 12:32:17 -07:00
export default ScheduledStatuses ;