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 { FormattedMessage } from 'react-intl' ;
2022-01-10 14:17:52 -08:00
import { connect } from 'react-redux' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:17:52 -08:00
import { fetchFavourites } from 'soapbox/actions/interactions' ;
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' , 'favourited_by' , props . statusId ] ) ,
} ;
} ;
export default @ connect ( mapStateToProps )
class FavouritesModal extends React . PureComponent {
static propTypes = {
onClose : PropTypes . func . isRequired ,
statusId : PropTypes . string . isRequired ,
username : PropTypes . string . isRequired ,
dispatch : PropTypes . func . isRequired ,
accountIds : ImmutablePropTypes . orderedSet ,
} ;
fetchData = ( ) => {
const { dispatch , statusId } = this . props ;
dispatch ( fetchFavourites ( statusId ) ) ;
}
componentDidMount ( ) {
this . fetchData ( ) ;
}
2022-01-30 09:46:57 -08:00
onClickClose = ( ) => {
this . props . onClose ( 'FAVOURITES' ) ;
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 = 'empty_column.favourites' defaultMessage = 'No one has liked this post yet. When someone does, they will show up here.' / > ;
body = (
< ScrollableList
scrollKey = 'favourites'
emptyMessage = { emptyMessage }
2022-04-22 10:24:09 -07:00
itemClassName = 'pb-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.favourites' defaultMessage = 'likes' / > }
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
) ;
}
}