account.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import Avatar from './avatar';
  5. import DisplayName from './display_name';
  6. import Permalink from './permalink';
  7. import IconButton from './icon_button';
  8. import { defineMessages, injectIntl } from 'react-intl';
  9. import ImmutablePureComponent from 'react-immutable-pure-component';
  10. const messages = defineMessages({
  11. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  12. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  13. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
  14. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  15. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }
  16. });
  17. class Account extends ImmutablePureComponent {
  18. constructor (props, context) {
  19. super(props, context);
  20. this.handleFollow = this.handleFollow.bind(this);
  21. this.handleBlock = this.handleBlock.bind(this);
  22. this.handleMute = this.handleMute.bind(this);
  23. }
  24. handleFollow () {
  25. this.props.onFollow(this.props.account);
  26. }
  27. handleBlock () {
  28. this.props.onBlock(this.props.account);
  29. }
  30. handleMute () {
  31. this.props.onMute(this.props.account);
  32. }
  33. render () {
  34. const { account, me, intl } = this.props;
  35. if (!account) {
  36. return <div />;
  37. }
  38. let buttons;
  39. if (account.get('id') !== me && account.get('relationship', null) !== null) {
  40. const following = account.getIn(['relationship', 'following']);
  41. const requested = account.getIn(['relationship', 'requested']);
  42. const blocking = account.getIn(['relationship', 'blocking']);
  43. const muting = account.getIn(['relationship', 'muting']);
  44. if (requested) {
  45. buttons = <IconButton disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  46. } else if (blocking) {
  47. buttons = <IconButton active={true} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
  48. } else if (muting) {
  49. buttons = <IconButton active={true} icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />;
  50. } else {
  51. buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
  52. }
  53. }
  54. return (
  55. <div className='account'>
  56. <div className='account__wrapper'>
  57. <Permalink key={account.get('id')} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
  58. <div className='account__avatar-wrapper'><Avatar src={account.get('avatar')} staticSrc={account.get('avatar_static')} size={36} /></div>
  59. <DisplayName account={account} />
  60. </Permalink>
  61. <div className='account__relationship'>
  62. {buttons}
  63. </div>
  64. </div>
  65. </div>
  66. );
  67. }
  68. }
  69. Account.propTypes = {
  70. account: ImmutablePropTypes.map.isRequired,
  71. me: PropTypes.number.isRequired,
  72. onFollow: PropTypes.func.isRequired,
  73. onBlock: PropTypes.func.isRequired,
  74. onMute: PropTypes.func.isRequired,
  75. intl: PropTypes.object.isRequired
  76. }
  77. export default injectIntl(Account);