2022-01-06 05:43:58 -08:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { injectIntl , FormattedMessage , defineMessages } from 'react-intl' ;
import IconButton from 'soapbox/components/icon_button' ;
import LoadingIndicator from 'soapbox/components/loading_indicator' ;
import AccountContainer from 'soapbox/containers/account_container' ;
import ScrollableList from 'soapbox/components/scrollable_list' ;
import { fetchFavourites } from 'soapbox/actions/interactions' ;
const messages = defineMessages ( {
close : { id : 'lightbox.close' , defaultMessage : 'Close' } ,
} ) ;
const mapStateToProps = ( state , props ) => {
return {
accountIds : state . getIn ( [ 'user_lists' , 'favourited_by' , props . statusId ] ) ,
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
class FavouritesModal extends React . PureComponent {
2022-01-06 15:41:07 -08:00
static contextTypes = {
router : PropTypes . object ,
} ;
2022-01-06 05:43:58 -08:00
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 ,
} ;
fetchData = ( ) => {
const { dispatch , statusId } = this . props ;
dispatch ( fetchFavourites ( statusId ) ) ;
}
componentDidMount ( ) {
this . fetchData ( ) ;
2022-01-06 15:41:07 -08:00
this . unlistenHistory = this . context . router . history . listen ( ( _ , action ) => {
if ( action === 'PUSH' ) {
this . onClickClose ( null , true ) ;
}
} ) ;
}
componentWillUnmount ( ) {
if ( this . unlistenHistory ) {
this . unlistenHistory ( ) ;
}
2022-01-06 05:43:58 -08:00
}
2022-01-06 15:41:07 -08:00
onClickClose = ( _ , noPop ) => {
this . props . onClose ( 'FAVOURITES' , noPop ) ;
2022-01-06 05:43:58 -08:00
} ;
render ( ) {
const { intl , accountIds } = this . props ;
let body ;
if ( ! accountIds ) {
body = < LoadingIndicator / > ;
} 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 }
>
{ accountIds . map ( id =>
< AccountContainer key = { id } id = { id } withNote = { false } / > ,
) }
< / S c r o l l a b l e L i s t >
) ;
}
return (
< div className = 'modal-root__modal reactions-modal' >
< div className = 'compose-modal__header' >
< h3 className = 'compose-modal__header__title' >
< FormattedMessage id = 'column.favourites' defaultMessage = 'likes' / >
< / h 3 >
< IconButton
className = 'compose-modal__close'
title = { intl . formatMessage ( messages . close ) }
src = { require ( '@tabler/icons/icons/x.svg' ) }
onClick = { this . onClickClose } size = { 20 }
/ >
< / d i v >
{ body }
< / d i v >
) ;
}
}