compose_form_container.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { connect } from 'react-redux';
  2. import {
  3. changeCompose,
  4. submitCompose,
  5. clearComposeSuggestions,
  6. fetchComposeSuggestions,
  7. selectComposeSuggestion,
  8. changeComposeSpoilerText,
  9. insertEmojiCompose,
  10. uploadCompose,
  11. } from '../../../actions/compose';
  12. import ComposeForm from '../components/compose_form';
  13. const mapStateToProps = state => ({
  14. text: state.getIn(['compose', 'text']),
  15. suggestions: state.getIn(['compose', 'suggestions']),
  16. spoiler: state.getIn(['compose', 'spoiler']),
  17. spoilerText: state.getIn(['compose', 'spoiler_text']),
  18. privacy: state.getIn(['compose', 'privacy']),
  19. focusDate: state.getIn(['compose', 'focusDate']),
  20. caretPosition: state.getIn(['compose', 'caretPosition']),
  21. preselectDate: state.getIn(['compose', 'preselectDate']),
  22. isSubmitting: state.getIn(['compose', 'is_submitting']),
  23. isEditing: state.getIn(['compose', 'id']) !== null,
  24. isChangingUpload: state.getIn(['compose', 'is_changing_upload']),
  25. isUploading: state.getIn(['compose', 'is_uploading']),
  26. anyMedia: state.getIn(['compose', 'media_attachments']).size > 0,
  27. isInReply: state.getIn(['compose', 'in_reply_to']) !== null,
  28. lang: state.getIn(['compose', 'language']),
  29. });
  30. const mapDispatchToProps = (dispatch) => ({
  31. onChange (text) {
  32. dispatch(changeCompose(text));
  33. },
  34. onSubmit (router) {
  35. dispatch(submitCompose(router));
  36. },
  37. onClearSuggestions () {
  38. dispatch(clearComposeSuggestions());
  39. },
  40. onFetchSuggestions (token) {
  41. dispatch(fetchComposeSuggestions(token));
  42. },
  43. onSuggestionSelected (position, token, suggestion, path) {
  44. dispatch(selectComposeSuggestion(position, token, suggestion, path));
  45. },
  46. onChangeSpoilerText (checked) {
  47. dispatch(changeComposeSpoilerText(checked));
  48. },
  49. onPaste (files) {
  50. dispatch(uploadCompose(files));
  51. },
  52. onPickEmoji (position, data, needsSpace) {
  53. dispatch(insertEmojiCompose(position, data, needsSpace));
  54. },
  55. });
  56. export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);