2017-12-06 09:02:27 +11:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { makeGetAccount } from '../../../selectors';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2023-05-09 11:11:56 +10:00
|
|
|
import { Avatar } from '../../../components/avatar';
|
2017-12-06 09:02:27 +11:00
|
|
|
import DisplayName from '../../../components/display_name';
|
2023-05-09 11:11:56 +10:00
|
|
|
import { IconButton } from '../../../components/icon_button';
|
2017-12-06 09:02:27 +11:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { removeFromListEditor, addToListEditor } from '../../../actions/lists';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' },
|
|
|
|
add: { id: 'lists.account.add', defaultMessage: 'Add to list' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { accountId, added }) => ({
|
|
|
|
account: getAccount(state, accountId),
|
|
|
|
added: typeof added === 'undefined' ? state.getIn(['listEditor', 'accounts', 'items']).includes(accountId) : added,
|
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { accountId }) => ({
|
|
|
|
onRemove: () => dispatch(removeFromListEditor(accountId)),
|
|
|
|
onAdd: () => dispatch(addToListEditor(accountId)),
|
|
|
|
});
|
|
|
|
|
2018-09-15 01:59:48 +10:00
|
|
|
class Account extends ImmutablePureComponent {
|
2017-12-06 09:02:27 +11:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onRemove: PropTypes.func.isRequired,
|
|
|
|
onAdd: PropTypes.func.isRequired,
|
|
|
|
added: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
added: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { account, intl, onRemove, onAdd, added } = this.props;
|
|
|
|
|
|
|
|
let button;
|
|
|
|
|
|
|
|
if (added) {
|
|
|
|
button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
|
|
|
|
} else {
|
|
|
|
button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='account'>
|
|
|
|
<div className='account__wrapper'>
|
|
|
|
<div className='account__display-name'>
|
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
|
|
|
|
<DisplayName account={account} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{button}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(injectIntl(Account));
|