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.

141 lines
4.2 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 { fetchStatus } from '../../actions/statuses';
  5. import Immutable from 'immutable';
  6. import EmbeddedStatus from '../../components/status';
  7. import LoadingIndicator from '../../components/loading_indicator';
  8. import DetailedStatus from './components/detailed_status';
  9. import ActionBar from './components/action_bar';
  10. import Column from '../ui/components/column';
  11. import { favourite, reblog } from '../../actions/interactions';
  12. import {
  13. replyCompose,
  14. mentionCompose
  15. } from '../../actions/compose';
  16. import { deleteStatus } from '../../actions/statuses';
  17. import {
  18. makeGetStatus,
  19. getStatusAncestors,
  20. getStatusDescendants
  21. } from '../../selectors';
  22. import { ScrollContainer } from 'react-router-scroll';
  23. import ColumnBackButton from '../../components/column_back_button';
  24. import StatusContainer from '../../containers/status_container';
  25. import { openMedia } from '../../actions/modal';
  26. import { isMobile } from '../../is_mobile'
  27. const makeMapStateToProps = () => {
  28. const getStatus = makeGetStatus();
  29. const mapStateToProps = (state, props) => ({
  30. status: getStatus(state, Number(props.params.statusId)),
  31. ancestorsIds: state.getIn(['timelines', 'ancestors', Number(props.params.statusId)]),
  32. descendantsIds: state.getIn(['timelines', 'descendants', Number(props.params.statusId)]),
  33. me: state.getIn(['meta', 'me'])
  34. });
  35. return mapStateToProps;
  36. };
  37. const Status = React.createClass({
  38. contextTypes: {
  39. router: React.PropTypes.object
  40. },
  41. propTypes: {
  42. params: React.PropTypes.object.isRequired,
  43. dispatch: React.PropTypes.func.isRequired,
  44. status: ImmutablePropTypes.map,
  45. ancestorsIds: ImmutablePropTypes.list,
  46. descendantsIds: ImmutablePropTypes.list,
  47. me: React.PropTypes.number
  48. },
  49. mixins: [PureRenderMixin],
  50. componentWillMount () {
  51. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  52. },
  53. componentWillReceiveProps (nextProps) {
  54. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  55. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  56. }
  57. },
  58. handleFavouriteClick (status) {
  59. this.props.dispatch(favourite(status));
  60. },
  61. handleReplyClick (status) {
  62. this.props.dispatch(replyCompose(status, this.context.router));
  63. },
  64. handleReblogClick (status) {
  65. this.props.dispatch(reblog(status));
  66. },
  67. handleDeleteClick (status) {
  68. this.props.dispatch(deleteStatus(status.get('id')));
  69. },
  70. handleMentionClick (account) {
  71. this.props.dispatch(mentionCompose(account));
  72. if (isMobile(window.innerWidth)) {
  73. this.context.router.push('/statuses/new');
  74. }
  75. },
  76. handleOpenMedia (url) {
  77. this.props.dispatch(openMedia(url));
  78. },
  79. renderChildren (list) {
  80. return list.map(id => <StatusContainer key={id} id={id} />);
  81. },
  82. render () {
  83. let ancestors, descendants;
  84. const { status, ancestorsIds, descendantsIds, me } = this.props;
  85. if (status === null) {
  86. return (
  87. <Column>
  88. <LoadingIndicator />
  89. </Column>
  90. );
  91. }
  92. const account = status.get('account');
  93. if (ancestorsIds && ancestorsIds.size > 0) {
  94. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  95. }
  96. if (descendantsIds && descendantsIds.size > 0) {
  97. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  98. }
  99. return (
  100. <Column>
  101. <ColumnBackButton />
  102. <ScrollContainer scrollKey='thread'>
  103. <div className='scrollable'>
  104. {ancestors}
  105. <DetailedStatus status={status} me={me} onOpenMedia={this.handleOpenMedia} />
  106. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} />
  107. {descendants}
  108. </div>
  109. </ScrollContainer>
  110. </Column>
  111. );
  112. }
  113. });
  114. export default connect(makeMapStateToProps)(Status);