2021-06-27 11:59:10 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import Column from '../ui/components/column' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2021-06-27 15:04:23 -07:00
import ScrollableList from 'soapbox/components/scrollable_list' ;
2021-06-27 11:59:10 -07:00
import { fetchScheduledStatuses , expandScheduledStatuses } from '../../actions/scheduled_statuses' ;
2021-06-27 15:04:23 -07:00
import ScheduledStatus from './components/scheduled_status' ;
2021-06-27 11:59:10 -07:00
import { debounce } from 'lodash' ;
const messages = defineMessages ( {
2021-06-27 18:45:31 -07:00
heading : { id : 'column.scheduled_statuses' , defaultMessage : 'Scheduled Posts' } ,
2021-06-27 11:59:10 -07:00
} ) ;
const mapStateToProps = state => ( {
statusIds : state . getIn ( [ 'status_lists' , 'scheduled_statuses' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'scheduled_statuses' , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'scheduled_statuses' , 'next' ] ) ,
} ) ;
export default @ connect ( mapStateToProps )
@ injectIntl
class ScheduledStatuses extends ImmutablePureComponent {
static contextTypes = {
router : PropTypes . object ,
} ;
static propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
intl : PropTypes . object . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
} ;
componentDidMount ( ) {
const { dispatch } = this . props ;
dispatch ( fetchScheduledStatuses ( ) ) ;
}
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandScheduledStatuses ( ) ) ;
} , 300 , { leading : true } )
render ( ) {
2021-06-27 15:04:23 -07:00
const { intl , statusIds , hasMore , isLoading } = this . props ;
2021-06-27 11:59:10 -07:00
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 (
2021-06-27 22:06:04 -07:00
< Column icon = 'calendar' heading = { intl . formatMessage ( messages . heading ) } backBtnSlim >
2021-06-27 15:04:23 -07:00
< ScrollableList
scrollKey = 'scheduled_statuses'
2021-06-27 11:59:10 -07:00
emptyMessage = { emptyMessage }
2021-06-27 15:04:23 -07:00
isLoading = { isLoading }
hasMore = { hasMore }
>
{ statusIds . map ( id => < ScheduledStatus key = { id } statusId = { id } / > ) }
< / S c r o l l a b l e L i s t >
2021-06-27 11:59:10 -07:00
< / C o l u m n >
) ;
}
}