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.

139 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. },
  48. mixins: [PureRenderMixin],
  49. componentWillMount () {
  50. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  51. },
  52. componentWillReceiveProps (nextProps) {
  53. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  54. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  55. }
  56. },
  57. handleFavouriteClick (status) {
  58. this.props.dispatch(favourite(status));
  59. },
  60. handleReplyClick (status) {
  61. this.props.dispatch(replyCompose(status, this.context.router));
  62. },
  63. handleReblogClick (status) {
  64. this.props.dispatch(reblog(status));
  65. },
  66. handleDeleteClick (status) {
  67. this.props.dispatch(deleteStatus(status.get('id')));
  68. },
  69. handleMentionClick (account) {
  70. this.props.dispatch(mentionCompose(account));
  71. if (isMobile(window.innerWidth)) {
  72. this.context.router.push('/statuses/new');
  73. }
  74. },
  75. handleOpenMedia (url) {
  76. this.props.dispatch(openMedia(url));
  77. },
  78. renderChildren (list) {
  79. return list.map(id => <StatusContainer key={id} id={id} />);
  80. },
  81. render () {
  82. let ancestors, descendants;
  83. const { status, ancestorsIds, descendantsIds, me } = this.props;
  84. if (status === null) {
  85. return (
  86. <Column>
  87. <LoadingIndicator />
  88. </Column>
  89. );
  90. }
  91. const account = status.get('account');
  92. if (ancestorsIds && ancestorsIds.size > 0) {
  93. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  94. }
  95. if (descendantsIds && descendantsIds.size > 0) {
  96. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  97. }
  98. return (
  99. <Column>
  100. <ColumnBackButton />
  101. <ScrollContainer scrollKey='thread'>
  102. <div className='scrollable'>
  103. {ancestors}
  104. <DetailedStatus status={status} me={me} onOpenMedia={this.handleOpenMedia} />
  105. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} />
  106. {descendants}
  107. </div>
  108. </ScrollContainer>
  109. </Column>
  110. );
  111. }
  112. });
  113. export default connect(makeMapStateToProps)(Status);