You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.8 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import InnerHeader from 'flavours/glitch/features/account/components/header';
  5. import ActionBar from 'flavours/glitch/features/account/components/action_bar';
  6. import MissingIndicator from 'flavours/glitch/components/missing_indicator';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. import { FormattedMessage } from 'react-intl';
  9. import { NavLink } from 'react-router-dom';
  10. import MovedNote from './moved_note';
  11. export default class Header extends ImmutablePureComponent {
  12. static propTypes = {
  13. account: ImmutablePropTypes.map,
  14. onFollow: PropTypes.func.isRequired,
  15. onBlock: PropTypes.func.isRequired,
  16. onMention: PropTypes.func.isRequired,
  17. onDirect: PropTypes.func.isRequired,
  18. onReblogToggle: PropTypes.func.isRequired,
  19. onReport: PropTypes.func.isRequired,
  20. onMute: PropTypes.func.isRequired,
  21. onBlockDomain: PropTypes.func.isRequired,
  22. onUnblockDomain: PropTypes.func.isRequired,
  23. onEndorseToggle: PropTypes.func.isRequired,
  24. onAddToList: PropTypes.func.isRequired,
  25. hideTabs: PropTypes.bool,
  26. };
  27. static contextTypes = {
  28. router: PropTypes.object,
  29. };
  30. handleFollow = () => {
  31. this.props.onFollow(this.props.account);
  32. }
  33. handleBlock = () => {
  34. this.props.onBlock(this.props.account);
  35. }
  36. handleMention = () => {
  37. this.props.onMention(this.props.account, this.context.router.history);
  38. }
  39. handleDirect = () => {
  40. this.props.onDirect(this.props.account, this.context.router.history);
  41. }
  42. handleReport = () => {
  43. this.props.onReport(this.props.account);
  44. }
  45. handleReblogToggle = () => {
  46. this.props.onReblogToggle(this.props.account);
  47. }
  48. handleMute = () => {
  49. this.props.onMute(this.props.account);
  50. }
  51. handleBlockDomain = () => {
  52. const domain = this.props.account.get('acct').split('@')[1];
  53. if (!domain) return;
  54. this.props.onBlockDomain(domain);
  55. }
  56. handleUnblockDomain = () => {
  57. const domain = this.props.account.get('acct').split('@')[1];
  58. if (!domain) return;
  59. this.props.onUnblockDomain(domain);
  60. }
  61. handleEndorseToggle = () => {
  62. this.props.onEndorseToggle(this.props.account);
  63. }
  64. handleAddToList = () => {
  65. this.props.onAddToList(this.props.account);
  66. }
  67. render () {
  68. const { account, hideTabs } = this.props;
  69. if (account === null) {
  70. return <MissingIndicator />;
  71. }
  72. return (
  73. <div className='account-timeline__header'>
  74. {account.get('moved') && <MovedNote from={account} to={account.get('moved')} />}
  75. <InnerHeader
  76. account={account}
  77. onFollow={this.handleFollow}
  78. onBlock={this.handleBlock}
  79. />
  80. <ActionBar
  81. account={account}
  82. onBlock={this.handleBlock}
  83. onMention={this.handleMention}
  84. onDirect={this.handleDirect}
  85. onReblogToggle={this.handleReblogToggle}
  86. onReport={this.handleReport}
  87. onMute={this.handleMute}
  88. onBlockDomain={this.handleBlockDomain}
  89. onUnblockDomain={this.handleUnblockDomain}
  90. onEndorseToggle={this.handleEndorseToggle}
  91. onAddToList={this.handleAddToList}
  92. />
  93. {!hideTabs && (
  94. <div className='account__section-headline'>
  95. <NavLink exact to={`/accounts/${account.get('id')}`}><FormattedMessage id='account.posts' defaultMessage='Toots' /></NavLink>
  96. <NavLink exact to={`/accounts/${account.get('id')}/with_replies`}><FormattedMessage id='account.posts_with_replies' defaultMessage='Toots with replies' /></NavLink>
  97. <NavLink exact to={`/accounts/${account.get('id')}/media`}><FormattedMessage id='account.media' defaultMessage='Media' /></NavLink>
  98. </div>
  99. )}
  100. </div>
  101. );
  102. }
  103. }