about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/compose/containers/compose_form_container.jsx
blob: c027875cdc75346c95a9b8420ec577807888750b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { connect } from 'react-redux';
import ComposeForm from '../components/compose_form';
import {
  changeCompose,
  submitCompose,
  cancelReplyCompose,
  clearComposeSuggestions,
  fetchComposeSuggestions,
  selectComposeSuggestion,
  changeComposeSensitivity,
  changeComposeSpoilerness,
  changeComposeSpoilerText,
  changeComposeVisibility,
  changeComposeListability
} from '../../../actions/compose';
import { makeGetStatus } from '../../../selectors';

const makeMapStateToProps = () => {
  const getStatus = makeGetStatus();

  const mapStateToProps = function (state, props) {
    return {
      text: state.getIn(['compose', 'text']),
      suggestion_token: state.getIn(['compose', 'suggestion_token']),
      suggestions: state.getIn(['compose', 'suggestions']),
      sensitive: state.getIn(['compose', 'sensitive']),
      spoiler: state.getIn(['compose', 'spoiler']),
      spoiler_text: state.getIn(['compose', 'spoiler_text']),
      unlisted: state.getIn(['compose', 'unlisted'], ),
      private: state.getIn(['compose', 'private']),
      fileDropDate: state.getIn(['compose', 'fileDropDate']),
      is_submitting: state.getIn(['compose', 'is_submitting']),
      is_uploading: state.getIn(['compose', 'is_uploading']),
      in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])),
      media_count: state.getIn(['compose', 'media_attachments']).size,
      me: state.getIn(['compose', 'me']),
    };
  };

  return mapStateToProps;
};

const mapDispatchToProps = function (dispatch) {
  return {
    onChange (text) {
      dispatch(changeCompose(text));
    },

    onSubmit () {
      dispatch(submitCompose());
    },

    onCancelReply () {
      dispatch(cancelReplyCompose());
    },

    onClearSuggestions () {
      dispatch(clearComposeSuggestions());
    },

    onFetchSuggestions (token) {
      dispatch(fetchComposeSuggestions(token));
    },

    onSuggestionSelected (position, token, accountId) {
      dispatch(selectComposeSuggestion(position, token, accountId));
    },

    onChangeSensitivity (checked) {
      dispatch(changeComposeSensitivity(checked));
    },

    onChangeSpoilerness (checked) {
      dispatch(changeComposeSpoilerness(checked));
    },

    onChangeSpoilerText (checked) {
      dispatch(changeComposeSpoilerText(checked));
    },

    onChangeVisibility (checked) {
      dispatch(changeComposeVisibility(checked));
    },

    onChangeListability (checked) {
      dispatch(changeComposeListability(checked));
    }
  }
};

export default connect(makeMapStateToProps, mapDispatchToProps)(ComposeForm);