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.

100 lines
2.8 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. const makeMapStateToProps = () => {
  24. const getAccount = makeGetAccount();
  25. const mapStateToProps = (state, props) => ({
  26. account: getAccount(state, Number(props.params.accountId)),
  27. me: state.getIn(['meta', 'me'])
  28. });
  29. return mapStateToProps;
  30. };
  31. const Account = React.createClass({
  32. propTypes: {
  33. params: React.PropTypes.object.isRequired,
  34. dispatch: React.PropTypes.func.isRequired,
  35. account: ImmutablePropTypes.map,
  36. me: React.PropTypes.number.isRequired
  37. },
  38. mixins: [PureRenderMixin],
  39. componentWillMount () {
  40. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  41. },
  42. componentWillReceiveProps (nextProps) {
  43. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  44. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  45. }
  46. },
  47. handleFollow () {
  48. if (this.props.account.getIn(['relationship', 'following'])) {
  49. this.props.dispatch(unfollowAccount(this.props.account.get('id')));
  50. } else {
  51. this.props.dispatch(followAccount(this.props.account.get('id')));
  52. }
  53. },
  54. handleBlock () {
  55. if (this.props.account.getIn(['relationship', 'blocking'])) {
  56. this.props.dispatch(unblockAccount(this.props.account.get('id')));
  57. } else {
  58. this.props.dispatch(blockAccount(this.props.account.get('id')));
  59. }
  60. },
  61. handleMention () {
  62. this.props.dispatch(mentionCompose(this.props.account));
  63. },
  64. render () {
  65. const { account, me } = this.props;
  66. if (account === null) {
  67. return (
  68. <Column>
  69. <LoadingIndicator />
  70. </Column>
  71. );
  72. }
  73. return (
  74. <Column>
  75. <ColumnBackButton />
  76. <Header account={account} me={me} onFollow={this.handleFollow} />
  77. <ActionBar account={account} me={me} onBlock={this.handleBlock} onMention={this.handleMention} />
  78. {this.props.children}
  79. </Column>
  80. );
  81. }
  82. });
  83. export default connect(makeMapStateToProps)(Account);