闭社主体 forked from https://github.com/tootsuite/mastodon
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.

135 lines
4.0 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. const makeMapStateToProps = () => {
  27. const getStatus = makeGetStatus();
  28. const mapStateToProps = (state, props) => ({
  29. status: getStatus(state, Number(props.params.statusId)),
  30. ancestorsIds: state.getIn(['timelines', 'ancestors', Number(props.params.statusId)]),
  31. descendantsIds: state.getIn(['timelines', 'descendants', Number(props.params.statusId)]),
  32. me: state.getIn(['meta', 'me'])
  33. });
  34. return mapStateToProps;
  35. };
  36. const Status = React.createClass({
  37. contextTypes: {
  38. router: React.PropTypes.object
  39. },
  40. propTypes: {
  41. params: React.PropTypes.object.isRequired,
  42. dispatch: React.PropTypes.func.isRequired,
  43. status: ImmutablePropTypes.map,
  44. ancestorsIds: ImmutablePropTypes.list,
  45. descendantsIds: ImmutablePropTypes.list
  46. },
  47. mixins: [PureRenderMixin],
  48. componentWillMount () {
  49. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  50. },
  51. componentWillReceiveProps (nextProps) {
  52. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  53. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  54. }
  55. },
  56. handleFavouriteClick (status) {
  57. this.props.dispatch(favourite(status));
  58. },
  59. handleReplyClick (status) {
  60. this.props.dispatch(replyCompose(status, this.context.router));
  61. },
  62. handleReblogClick (status) {
  63. this.props.dispatch(reblog(status));
  64. },
  65. handleDeleteClick (status) {
  66. this.props.dispatch(deleteStatus(status.get('id')));
  67. },
  68. handleMentionClick (account) {
  69. this.props.dispatch(mentionCompose(account));
  70. },
  71. handleOpenMedia (url) {
  72. this.props.dispatch(openMedia(url));
  73. },
  74. renderChildren (list) {
  75. return list.map(id => <StatusContainer key={id} id={id} />);
  76. },
  77. render () {
  78. let ancestors, descendants;
  79. const { status, ancestorsIds, descendantsIds, me } = this.props;
  80. if (status === null) {
  81. return (
  82. <Column>
  83. <LoadingIndicator />
  84. </Column>
  85. );
  86. }
  87. const account = status.get('account');
  88. if (ancestorsIds && ancestorsIds.size > 0) {
  89. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  90. }
  91. if (descendantsIds && descendantsIds.size > 0) {
  92. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  93. }
  94. return (
  95. <Column>
  96. <ColumnBackButton />
  97. <ScrollContainer scrollKey='thread'>
  98. <div className='scrollable'>
  99. {ancestors}
  100. <DetailedStatus status={status} me={me} onOpenMedia={this.handleOpenMedia} />
  101. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} />
  102. {descendants}
  103. </div>
  104. </ScrollContainer>
  105. </Column>
  106. );
  107. }
  108. });
  109. export default connect(makeMapStateToProps)(Status);