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