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.

133 lines
4.1 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 { deleteStatus } from '../../actions/statuses';
  14. import { replyCompose } from '../../actions/compose';
  15. import {
  16. favourite,
  17. reblog,
  18. unreblog,
  19. unfavourite
  20. } from '../../actions/interactions';
  21. import Header from './components/header';
  22. import {
  23. selectStatus,
  24. selectAccount
  25. } from '../../reducers/timelines';
  26. import StatusList from '../../components/status_list';
  27. import LoadingIndicator from '../../components/loading_indicator';
  28. import Immutable from 'immutable';
  29. import ActionBar from './components/action_bar';
  30. import Column from '../ui/components/column';
  31. function selectStatuses(state, accountId) {
  32. return state.getIn(['timelines', 'accounts_timelines', accountId], Immutable.List([])).map(id => selectStatus(state, id)).filterNot(status => status === null);
  33. };
  34. const mapStateToProps = (state, props) => ({
  35. account: selectAccount(state, Number(props.params.accountId)),
  36. statuses: selectStatuses(state, Number(props.params.accountId)),
  37. me: state.getIn(['timelines', 'me'])
  38. });
  39. const Account = React.createClass({
  40. propTypes: {
  41. params: React.PropTypes.object.isRequired,
  42. dispatch: React.PropTypes.func.isRequired,
  43. account: ImmutablePropTypes.map,
  44. statuses: ImmutablePropTypes.list
  45. },
  46. mixins: [PureRenderMixin],
  47. componentWillMount () {
  48. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  49. this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
  50. },
  51. componentWillReceiveProps(nextProps) {
  52. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  53. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  54. this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
  55. }
  56. },
  57. handleFollow () {
  58. if (this.props.account.getIn(['relationship', 'following'])) {
  59. this.props.dispatch(unfollowAccount(this.props.account.get('id')));
  60. } else {
  61. this.props.dispatch(followAccount(this.props.account.get('id')));
  62. }
  63. },
  64. handleBlock () {
  65. if (this.props.account.getIn(['relationship', 'blocking'])) {
  66. this.props.dispatch(unblockAccount(this.props.account.get('id')));
  67. } else {
  68. this.props.dispatch(blockAccount(this.props.account.get('id')));
  69. }
  70. },
  71. handleReply (status) {
  72. this.props.dispatch(replyCompose(status));
  73. },
  74. handleReblog (status) {
  75. if (status.get('reblogged')) {
  76. this.props.dispatch(unreblog(status));
  77. } else {
  78. this.props.dispatch(reblog(status));
  79. }
  80. },
  81. handleFavourite (status) {
  82. if (status.get('favourited')) {
  83. this.props.dispatch(unfavourite(status));
  84. } else {
  85. this.props.dispatch(favourite(status));
  86. }
  87. },
  88. handleDelete (status) {
  89. this.props.dispatch(deleteStatus(status.get('id')));
  90. },
  91. handleScrollToBottom () {
  92. this.props.dispatch(expandAccountTimeline(this.props.account.get('id')));
  93. },
  94. render () {
  95. const { account, statuses, me } = this.props;
  96. if (account === null) {
  97. return (
  98. <Column>
  99. <LoadingIndicator />
  100. </Column>
  101. );
  102. }
  103. return (
  104. <Column>
  105. <div style={{ display: 'flex', flexDirection: 'column', 'flex': '0 0 auto', height: '100%' }}>
  106. <Header account={account} />
  107. <ActionBar account={account} me={me} onFollow={this.handleFollow} onBlock={this.handleBlock} />
  108. <StatusList statuses={statuses} me={me} onScrollToBottom={this.handleScrollToBottom} onReply={this.handleReply} onReblog={this.handleReblog} onFavourite={this.handleFavourite} onDelete={this.handleDelete} />
  109. </div>
  110. </Column>
  111. );
  112. }
  113. });
  114. export default connect(mapStateToProps)(Account);