2022-01-06 05:43:58 -08:00
import PropTypes from 'prop-types' ;
2022-01-10 14:17:52 -08:00
import React from 'react' ;
2022-01-06 05:43:58 -08:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2022-03-21 11:09:01 -07:00
import { injectIntl , FormattedMessage } from 'react-intl' ;
2022-01-10 14:17:52 -08:00
import { connect } from 'react-redux' ;
2022-03-17 18:17:28 -07:00
import { withRouter } from 'react-router-dom' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:17:52 -08:00
import { fetchReblogs } from 'soapbox/actions/interactions' ;
import { fetchStatus } from 'soapbox/actions/statuses' ;
2022-01-06 05:43:58 -08:00
import ScrollableList from 'soapbox/components/scrollable_list' ;
2022-03-21 11:09:01 -07:00
import { Modal , Spinner } from 'soapbox/components/ui' ;
2022-01-10 14:17:52 -08:00
import AccountContainer from 'soapbox/containers/account_container' ;
2022-01-06 05:43:58 -08:00
const mapStateToProps = ( state , props ) => {
return {
accountIds : state . getIn ( [ 'user_lists' , 'reblogged_by' , props . statusId ] ) ,
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
2022-03-17 18:17:28 -07:00
@ withRouter
2022-01-06 05:43:58 -08:00
class ReblogsModal extends React . PureComponent {
static propTypes = {
onClose : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
statusId : PropTypes . string . isRequired ,
username : PropTypes . string . isRequired ,
dispatch : PropTypes . func . isRequired ,
accountIds : ImmutablePropTypes . orderedSet ,
2022-03-17 18:17:28 -07:00
history : PropTypes . object ,
2022-01-06 05:43:58 -08:00
} ;
fetchData = ( ) => {
const { dispatch , statusId } = this . props ;
dispatch ( fetchReblogs ( statusId ) ) ;
dispatch ( fetchStatus ( statusId ) ) ;
}
componentDidMount ( ) {
this . fetchData ( ) ;
2022-03-17 18:17:28 -07:00
this . unlistenHistory = this . props . history . listen ( ( _ , action ) => {
2022-01-06 15:41:07 -08:00
if ( action === 'PUSH' ) {
this . onClickClose ( null , true ) ;
}
} ) ;
}
componentWillUnmount ( ) {
if ( this . unlistenHistory ) {
this . unlistenHistory ( ) ;
}
2022-01-06 05:43:58 -08:00
}
2022-01-30 09:46:57 -08:00
onClickClose = ( ) => {
this . props . onClose ( 'REBLOGS' ) ;
2022-01-06 05:43:58 -08:00
} ;
render ( ) {
2022-03-21 11:09:01 -07:00
const { accountIds } = this . props ;
2022-01-06 05:43:58 -08:00
let body ;
if ( ! accountIds ) {
2022-03-21 11:09:01 -07:00
body = < Spinner / > ;
2022-01-06 05:43:58 -08:00
} else {
const emptyMessage = < FormattedMessage id = 'status.reblogs.empty' defaultMessage = 'No one has reposted this post yet. When someone does, they will show up here.' / > ;
body = (
< ScrollableList
scrollKey = 'reblogs'
emptyMessage = { emptyMessage }
2022-03-21 11:09:01 -07:00
className = 'space-y-3'
2022-01-06 05:43:58 -08:00
>
{ accountIds . map ( id =>
2022-03-21 11:09:01 -07:00
< AccountContainer key = { id } id = { id } / > ,
2022-01-06 05:43:58 -08:00
) }
< / S c r o l l a b l e L i s t >
) ;
}
return (
2022-03-21 11:09:01 -07:00
< Modal
title = { < FormattedMessage id = 'column.reblogs' defaultMessage = 'Reposts' / > }
onClose = { this . onClickClose }
>
2022-01-06 05:43:58 -08:00
{ body }
2022-03-21 11:09:01 -07:00
< / M o d a l >
2022-01-06 05:43:58 -08:00
) ;
}
}