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.

79 lines
2.2 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. changeComposeVisibility,
  12. changeComposeListability
  13. } from '../../../actions/compose';
  14. import { makeGetStatus } from '../../../selectors';
  15. const makeMapStateToProps = () => {
  16. const getStatus = makeGetStatus();
  17. const mapStateToProps = function (state, props) {
  18. return {
  19. text: state.getIn(['compose', 'text']),
  20. suggestion_token: state.getIn(['compose', 'suggestion_token']),
  21. suggestions: state.getIn(['compose', 'suggestions']),
  22. sensitive: state.getIn(['compose', 'sensitive']),
  23. unlisted: state.getIn(['compose', 'unlisted']),
  24. private: state.getIn(['compose', 'private']),
  25. fileDropDate: state.getIn(['compose', 'fileDropDate']),
  26. is_submitting: state.getIn(['compose', 'is_submitting']),
  27. is_uploading: state.getIn(['compose', 'is_uploading']),
  28. in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])),
  29. media_count: state.getIn(['compose', 'media_attachments']).size,
  30. me: state.getIn(['compose', 'me'])
  31. };
  32. };
  33. return mapStateToProps;
  34. };
  35. const mapDispatchToProps = function (dispatch) {
  36. return {
  37. onChange (text) {
  38. dispatch(changeCompose(text));
  39. },
  40. onSubmit () {
  41. dispatch(submitCompose());
  42. },
  43. onCancelReply () {
  44. dispatch(cancelReplyCompose());
  45. },
  46. onClearSuggestions () {
  47. dispatch(clearComposeSuggestions());
  48. },
  49. onFetchSuggestions (token) {
  50. dispatch(fetchComposeSuggestions(token));
  51. },
  52. onSuggestionSelected (position, token, accountId) {
  53. dispatch(selectComposeSuggestion(position, token, accountId));
  54. },
  55. onChangeSensitivity (checked) {
  56. dispatch(changeComposeSensitivity(checked));
  57. },
  58. onChangeVisibility (checked) {
  59. dispatch(changeComposeVisibility(checked));
  60. },
  61. onChangeListability (checked) {
  62. dispatch(changeComposeListability(checked));
  63. }
  64. }
  65. };
  66. export default connect(makeMapStateToProps, mapDispatchToProps)(ComposeForm);