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.

108 lines
3.0 KiB

8 years ago
  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import {
  5. fetchAccount,
  6. followAccount,
  7. unfollowAccount,
  8. blockAccount,
  9. unblockAccount,
  10. fetchAccountTimeline,
  11. expandAccountTimeline
  12. } from '../../actions/accounts';
  13. import { mentionCompose } from '../../actions/compose';
  14. import Header from './components/header';
  15. import {
  16. getAccountTimeline,
  17. makeGetAccount
  18. } from '../../selectors';
  19. import LoadingIndicator from '../../components/loading_indicator';
  20. import ActionBar from './components/action_bar';
  21. import Column from '../ui/components/column';
  22. import ColumnBackButton from '../../components/column_back_button';
  23. import { isMobile } from '../../is_mobile'
  24. const makeMapStateToProps = () => {
  25. const getAccount = makeGetAccount();
  26. const mapStateToProps = (state, props) => ({
  27. account: getAccount(state, Number(props.params.accountId)),
  28. me: state.getIn(['meta', 'me'])
  29. });
  30. return mapStateToProps;
  31. };
  32. const Account = React.createClass({
  33. contextTypes: {
  34. router: React.PropTypes.object
  35. },
  36. propTypes: {
  37. params: React.PropTypes.object.isRequired,
  38. dispatch: React.PropTypes.func.isRequired,
  39. account: ImmutablePropTypes.map,
  40. me: React.PropTypes.number.isRequired
  41. },
  42. mixins: [PureRenderMixin],
  43. componentWillMount () {
  44. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  45. },
  46. componentWillReceiveProps (nextProps) {
  47. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  48. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  49. }
  50. },
  51. handleFollow () {
  52. if (this.props.account.getIn(['relationship', 'following'])) {
  53. this.props.dispatch(unfollowAccount(this.props.account.get('id')));
  54. } else {
  55. this.props.dispatch(followAccount(this.props.account.get('id')));
  56. }
  57. },
  58. handleBlock () {
  59. if (this.props.account.getIn(['relationship', 'blocking'])) {
  60. this.props.dispatch(unblockAccount(this.props.account.get('id')));
  61. } else {
  62. this.props.dispatch(blockAccount(this.props.account.get('id')));
  63. }
  64. },
  65. handleMention () {
  66. this.props.dispatch(mentionCompose(this.props.account));
  67. if (isMobile(window.innerWidth)) {
  68. this.context.router.push('/statuses/new');
  69. }
  70. },
  71. render () {
  72. const { account, me } = this.props;
  73. if (account === null) {
  74. return (
  75. <Column>
  76. <LoadingIndicator />
  77. </Column>
  78. );
  79. }
  80. return (
  81. <Column>
  82. <ColumnBackButton />
  83. <Header account={account} me={me} onFollow={this.handleFollow} />
  84. <ActionBar account={account} me={me} onBlock={this.handleBlock} onMention={this.handleMention} />
  85. {this.props.children}
  86. </Column>
  87. );
  88. }
  89. });
  90. export default connect(makeMapStateToProps)(Account);