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.
 
 
 
 

200 lines
5.9 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { fetchStatus } from '../../actions/statuses';
  6. import MissingIndicator from '../../components/missing_indicator';
  7. import DetailedStatus from './components/detailed_status';
  8. import ActionBar from './components/action_bar';
  9. import Column from '../ui/components/column';
  10. import {
  11. favourite,
  12. unfavourite,
  13. reblog,
  14. unreblog,
  15. } from '../../actions/interactions';
  16. import {
  17. replyCompose,
  18. mentionCompose,
  19. } from '../../actions/compose';
  20. import { deleteStatus } from '../../actions/statuses';
  21. import { initReport } from '../../actions/reports';
  22. import { makeGetStatus } 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 { openModal } from '../../actions/modal';
  27. import { defineMessages, injectIntl } from 'react-intl';
  28. import ImmutablePureComponent from 'react-immutable-pure-component';
  29. const messages = defineMessages({
  30. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  31. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  32. });
  33. const makeMapStateToProps = () => {
  34. const getStatus = makeGetStatus();
  35. const mapStateToProps = (state, props) => ({
  36. status: getStatus(state, Number(props.params.statusId)),
  37. ancestorsIds: state.getIn(['contexts', 'ancestors', Number(props.params.statusId)]),
  38. descendantsIds: state.getIn(['contexts', 'descendants', Number(props.params.statusId)]),
  39. me: state.getIn(['meta', 'me']),
  40. boostModal: state.getIn(['meta', 'boost_modal']),
  41. deleteModal: state.getIn(['meta', 'delete_modal']),
  42. autoPlayGif: state.getIn(['meta', 'auto_play_gif']),
  43. });
  44. return mapStateToProps;
  45. };
  46. class Status extends ImmutablePureComponent {
  47. static contextTypes = {
  48. router: PropTypes.object,
  49. };
  50. static propTypes = {
  51. params: PropTypes.object.isRequired,
  52. dispatch: PropTypes.func.isRequired,
  53. status: ImmutablePropTypes.map,
  54. ancestorsIds: ImmutablePropTypes.list,
  55. descendantsIds: ImmutablePropTypes.list,
  56. me: PropTypes.number,
  57. boostModal: PropTypes.bool,
  58. deleteModal: PropTypes.bool,
  59. autoPlayGif: PropTypes.bool,
  60. intl: PropTypes.object.isRequired,
  61. };
  62. componentWillMount () {
  63. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  64. }
  65. componentWillReceiveProps (nextProps) {
  66. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  67. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  68. }
  69. }
  70. handleFavouriteClick = (status) => {
  71. if (status.get('favourited')) {
  72. this.props.dispatch(unfavourite(status));
  73. } else {
  74. this.props.dispatch(favourite(status));
  75. }
  76. }
  77. handleReplyClick = (status) => {
  78. this.props.dispatch(replyCompose(status, this.context.router.history));
  79. }
  80. handleModalReblog = (status) => {
  81. this.props.dispatch(reblog(status));
  82. }
  83. handleReblogClick = (status, e) => {
  84. if (status.get('reblogged')) {
  85. this.props.dispatch(unreblog(status));
  86. } else {
  87. if (e.shiftKey || !this.props.boostModal) {
  88. this.handleModalReblog(status);
  89. } else {
  90. this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
  91. }
  92. }
  93. }
  94. handleDeleteClick = (status) => {
  95. const { dispatch, intl } = this.props;
  96. if (!this.props.deleteModal) {
  97. dispatch(deleteStatus(status.get('id')));
  98. } else {
  99. dispatch(openModal('CONFIRM', {
  100. message: intl.formatMessage(messages.deleteMessage),
  101. confirm: intl.formatMessage(messages.deleteConfirm),
  102. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  103. }));
  104. }
  105. }
  106. handleMentionClick = (account, router) => {
  107. this.props.dispatch(mentionCompose(account, router));
  108. }
  109. handleOpenMedia = (media, index) => {
  110. this.props.dispatch(openModal('MEDIA', { media, index }));
  111. }
  112. handleOpenVideo = (media, time) => {
  113. this.props.dispatch(openModal('VIDEO', { media, time }));
  114. }
  115. handleReport = (status) => {
  116. this.props.dispatch(initReport(status.get('account'), status));
  117. }
  118. renderChildren (list) {
  119. return list.map(id => <StatusContainer key={id} id={id} />);
  120. }
  121. render () {
  122. let ancestors, descendants;
  123. const { status, ancestorsIds, descendantsIds, me, autoPlayGif } = this.props;
  124. if (status === null) {
  125. return (
  126. <Column>
  127. <ColumnBackButton />
  128. <MissingIndicator />
  129. </Column>
  130. );
  131. }
  132. if (ancestorsIds && ancestorsIds.size > 0) {
  133. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  134. }
  135. if (descendantsIds && descendantsIds.size > 0) {
  136. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  137. }
  138. return (
  139. <Column>
  140. <ColumnBackButton />
  141. <ScrollContainer scrollKey='thread'>
  142. <div className='scrollable detailed-status__wrapper'>
  143. {ancestors}
  144. <DetailedStatus
  145. status={status}
  146. autoPlayGif={autoPlayGif}
  147. me={me}
  148. onOpenVideo={this.handleOpenVideo}
  149. onOpenMedia={this.handleOpenMedia}
  150. />
  151. <ActionBar
  152. status={status}
  153. me={me}
  154. onReply={this.handleReplyClick}
  155. onFavourite={this.handleFavouriteClick}
  156. onReblog={this.handleReblogClick}
  157. onDelete={this.handleDeleteClick}
  158. onMention={this.handleMentionClick}
  159. onReport={this.handleReport}
  160. />
  161. {descendants}
  162. </div>
  163. </ScrollContainer>
  164. </Column>
  165. );
  166. }
  167. }
  168. export default injectIntl(connect(makeMapStateToProps)(Status));