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.

91 lines
2.5 KiB

  1. import { connect } from 'react-redux';
  2. import ComposeForm from '../components/compose_form';
  3. import {
  4. changeCompose,
  5. submitCompose,
  6. cancelReplyCompose,
  7. clearComposeSuggestions,
  8. fetchComposeSuggestions,
  9. selectComposeSuggestion,
  10. changeComposeSensitivity,
  11. changeComposeSpoilerness,
  12. changeComposeSpoilerText,
  13. changeComposeVisibility,
  14. changeComposeListability
  15. } from '../../../actions/compose';
  16. import { makeGetStatus } from '../../../selectors';
  17. const makeMapStateToProps = () => {
  18. const getStatus = makeGetStatus();
  19. const mapStateToProps = function (state, props) {
  20. return {
  21. text: state.getIn(['compose', 'text']),
  22. suggestion_token: state.getIn(['compose', 'suggestion_token']),
  23. suggestions: state.getIn(['compose', 'suggestions']),
  24. sensitive: state.getIn(['compose', 'sensitive']),
  25. spoiler: state.getIn(['compose', 'spoiler']),
  26. spoiler_text: state.getIn(['compose', 'spoiler_text']),
  27. unlisted: state.getIn(['compose', 'unlisted'], ),
  28. private: state.getIn(['compose', 'private']),
  29. fileDropDate: state.getIn(['compose', 'fileDropDate']),
  30. is_submitting: state.getIn(['compose', 'is_submitting']),
  31. is_uploading: state.getIn(['compose', 'is_uploading']),
  32. in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])),
  33. media_count: state.getIn(['compose', 'media_attachments']).size,
  34. me: state.getIn(['compose', 'me']),
  35. };
  36. };
  37. return mapStateToProps;
  38. };
  39. const mapDispatchToProps = function (dispatch) {
  40. return {
  41. onChange (text) {
  42. dispatch(changeCompose(text));
  43. },
  44. onSubmit () {
  45. dispatch(submitCompose());
  46. },
  47. onCancelReply () {
  48. dispatch(cancelReplyCompose());
  49. },
  50. onClearSuggestions () {
  51. dispatch(clearComposeSuggestions());
  52. },
  53. onFetchSuggestions (token) {
  54. dispatch(fetchComposeSuggestions(token));
  55. },
  56. onSuggestionSelected (position, token, accountId) {
  57. dispatch(selectComposeSuggestion(position, token, accountId));
  58. },
  59. onChangeSensitivity (checked) {
  60. dispatch(changeComposeSensitivity(checked));
  61. },
  62. onChangeSpoilerness (checked) {
  63. dispatch(changeComposeSpoilerness(checked));
  64. },
  65. onChangeSpoilerText (checked) {
  66. dispatch(changeComposeSpoilerText(checked));
  67. },
  68. onChangeVisibility (checked) {
  69. dispatch(changeComposeVisibility(checked));
  70. },
  71. onChangeListability (checked) {
  72. dispatch(changeComposeListability(checked));
  73. }
  74. }
  75. };
  76. export default connect(makeMapStateToProps, mapDispatchToProps)(ComposeForm);