闭社主体 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.

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