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.
 
 
 
 

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