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.

80 lines
2.3 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 { getAccountTimeline } from '../../selectors';
  5. import {
  6. fetchAccountTimeline,
  7. expandAccountTimeline
  8. } from '../../actions/accounts';
  9. import { deleteStatus } from '../../actions/statuses';
  10. import { replyCompose } from '../../actions/compose';
  11. import {
  12. favourite,
  13. reblog,
  14. unreblog,
  15. unfavourite
  16. } from '../../actions/interactions';
  17. import StatusList from '../../components/status_list';
  18. const mapStateToProps = (state, props) => ({
  19. statuses: getAccountTimeline(state, Number(props.params.accountId)),
  20. me: state.getIn(['timelines', 'me'])
  21. });
  22. const AccountTimeline = React.createClass({
  23. propTypes: {
  24. params: React.PropTypes.object.isRequired,
  25. dispatch: React.PropTypes.func.isRequired,
  26. statuses: ImmutablePropTypes.list
  27. },
  28. mixins: [PureRenderMixin],
  29. componentWillMount () {
  30. this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
  31. },
  32. componentWillReceiveProps(nextProps) {
  33. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  34. this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
  35. }
  36. },
  37. handleReply (status) {
  38. this.props.dispatch(replyCompose(status));
  39. },
  40. handleReblog (status) {
  41. if (status.get('reblogged')) {
  42. this.props.dispatch(unreblog(status));
  43. } else {
  44. this.props.dispatch(reblog(status));
  45. }
  46. },
  47. handleFavourite (status) {
  48. if (status.get('favourited')) {
  49. this.props.dispatch(unfavourite(status));
  50. } else {
  51. this.props.dispatch(favourite(status));
  52. }
  53. },
  54. handleDelete (status) {
  55. this.props.dispatch(deleteStatus(status.get('id')));
  56. },
  57. handleScrollToBottom () {
  58. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  59. },
  60. render () {
  61. const { statuses, me } = this.props;
  62. return <StatusList statuses={statuses} me={me} onScrollToBottom={this.handleScrollToBottom} onReply={this.handleReply} onReblog={this.handleReblog} onFavourite={this.handleFavourite} onDelete={this.handleDelete} />
  63. }
  64. });
  65. export default connect(mapStateToProps)(AccountTimeline);