bigbuffet-rw/app/soapbox/features/ui/components/favourites_modal.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
2022-03-21 11:09:01 -07:00
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { fetchFavourites } from 'soapbox/actions/interactions';
import ScrollableList from 'soapbox/components/scrollable_list';
2022-03-21 11:09:01 -07:00
import { Modal, Spinner } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container';
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();
}
onClickClose = () => {
this.props.onClose('FAVOURITES');
};
render() {
2022-03-21 11:09:01 -07:00
const { accountIds } = this.props;
let body;
if (!accountIds) {
2022-03-21 11:09:01 -07:00
body = <Spinner />;
} 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-03-21 11:09:01 -07:00
className='space-y-3'
>
{accountIds.map(id =>
2022-03-21 11:09:01 -07:00
<AccountContainer key={id} id={id} />,
)}
</ScrollableList>
);
}
return (
2022-03-21 11:09:01 -07:00
<Modal
title={<FormattedMessage id='column.favourites' defaultMessage='likes' />}
onClose={this.onClickClose}
>
{body}
2022-03-21 11:09:01 -07:00
</Modal>
);
}
}