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.

90 lines
2.5 KiB

  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 Header from './components/header';
  14. import {
  15. getAccountTimeline,
  16. getAccount
  17. } from '../../selectors';
  18. import LoadingIndicator from '../../components/loading_indicator';
  19. import ActionBar from './components/action_bar';
  20. import Column from '../ui/components/column';
  21. import ColumnBackButton from '../../components/column_back_button';
  22. const mapStateToProps = (state, props) => ({
  23. account: getAccount(state, Number(props.params.accountId)),
  24. me: state.getIn(['timelines', 'me'])
  25. });
  26. const Account = React.createClass({
  27. propTypes: {
  28. params: React.PropTypes.object.isRequired,
  29. dispatch: React.PropTypes.func.isRequired,
  30. account: ImmutablePropTypes.map,
  31. me: React.PropTypes.number.isRequired
  32. },
  33. mixins: [PureRenderMixin],
  34. componentWillMount () {
  35. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  36. },
  37. componentWillReceiveProps(nextProps) {
  38. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  39. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  40. }
  41. },
  42. handleFollow () {
  43. if (this.props.account.getIn(['relationship', 'following'])) {
  44. this.props.dispatch(unfollowAccount(this.props.account.get('id')));
  45. } else {
  46. this.props.dispatch(followAccount(this.props.account.get('id')));
  47. }
  48. },
  49. handleBlock () {
  50. if (this.props.account.getIn(['relationship', 'blocking'])) {
  51. this.props.dispatch(unblockAccount(this.props.account.get('id')));
  52. } else {
  53. this.props.dispatch(blockAccount(this.props.account.get('id')));
  54. }
  55. },
  56. render () {
  57. const { account, me } = this.props;
  58. if (account === null) {
  59. return (
  60. <Column>
  61. <LoadingIndicator />
  62. </Column>
  63. );
  64. }
  65. return (
  66. <Column>
  67. <ColumnBackButton />
  68. <Header account={account} me={me} />
  69. <ActionBar account={account} me={me} onFollow={this.handleFollow} onBlock={this.handleBlock} />
  70. {this.props.children}
  71. </Column>
  72. );
  73. }
  74. });
  75. export default connect(mapStateToProps)(Account);