import React from 'react';
import { connect } from 'react-redux';
import { List as ImmutableList } from 'immutable';
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, fetchReactions } from 'soapbox/actions/interactions';
const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' },
});
const mapStateToProps = (state, props) => {
const favourites = state.getIn(['user_lists', 'favourited_by', props.statusId]);
const reactions = state.getIn(['user_lists', 'reactions', props.statusId]);
const allReactions = favourites && reactions && ImmutableList(favourites ? [{ accounts: favourites, count: favourites.size, name: '👍' }] : []).concat(reactions || []);
return {
reactions: allReactions,
};
};
export default @connect(mapStateToProps)
@injectIntl
class ReactionsModal extends React.PureComponent {
static propTypes = {
onClose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
statusId: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
reaction: PropTypes.string,
dispatch: PropTypes.func.isRequired,
reactions: ImmutablePropTypes.list,
};
state = {
reaction: this.props.reaction,
}
fetchData = () => {
const { dispatch, statusId } = this.props;
dispatch(fetchFavourites(statusId));
dispatch(fetchReactions(statusId));
}
componentDidMount() {
this.fetchData();
}
onClickClose = () => {
this.props.onClose('REACTIONS');
};
handleFilterChange = (reaction) => () => {
this.setState({ reaction });
};
render() {
const { intl, reactions } = this.props;
const { reaction } = this.state;
const accounts = reactions && (reaction
? reactions.find(reaction => reaction.name === this.state.reaction).accounts.map(account => ({ id: account, reaction: this.state.reaction }))
: reactions.map(reaction => reaction.accounts.map(account => ({ id: account, reaction: reaction.name }))).flatten());
let body;
if (!accounts) {
body =