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

84 lines
2.1 KiB
JavaScript
Raw Normal View History

import { OrderedSet as ImmutableOrderedSet } from 'immutable';
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
2022-03-21 11:09:01 -07:00
import { injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { fetchStatusWithContext } from 'soapbox/actions/statuses';
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';
import { makeGetStatus } from 'soapbox/selectors';
const mapStateToProps = (state, props) => {
const getStatus = makeGetStatus();
const status = getStatus(state, {
id: props.statusId,
username: props.username,
});
return {
accountIds: status ? ImmutableOrderedSet(status.get('mentions').map(m => m.get('id'))) : null,
};
};
export default @connect(mapStateToProps)
@injectIntl
class MentionsModal 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,
};
fetchData = () => {
const { dispatch, statusId } = this.props;
dispatch(fetchStatusWithContext(statusId));
}
componentDidMount() {
this.fetchData();
}
onClickClose = () => {
this.props.onClose('MENTIONS');
};
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 {
body = (
<ScrollableList
scrollKey='mentions'
itemClassName='pb-3'
>
{accountIds.map(id =>
<AccountContainer key={id} id={id} withNote={false} />,
)}
</ScrollableList>
);
}
return (
2022-03-21 11:09:01 -07:00
<Modal
title={<FormattedMessage id='column.mentions' defaultMessage='Mentions' />}
onClose={this.onClickClose}
>
{body}
2022-03-21 11:09:01 -07:00
</Modal>
);
}
}