The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

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