about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/ui/containers/compose_form_container.jsx
blob: a092a1e8e58a55f0d2ca54ee4c47f3151c750b5a (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
import { connect }                                          from 'react-redux';
import ComposeForm                                          from '../components/compose_form';
import { changeCompose, submitCompose, cancelReplyCompose } from '../../../actions/compose';

function selectStatus(state) {
  let statusId = state.getIn(['compose', 'in_reply_to'], null);

  if (statusId === null) {
    return null;
  }

  let status = state.getIn(['timelines', 'statuses', statusId]);
  status = status.set('account', state.getIn(['timelines', 'accounts', status.get('account')]));

  return status;
};

const mapStateToProps = function (state, props) {
  return {
    text: state.getIn(['compose', 'text']),
    is_submitting: state.getIn(['compose', 'is_submitting']),
    in_reply_to: selectStatus(state)
  };
};

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

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

    onCancelReply: function () {
      dispatch(cancelReplyCompose());
    }
  }
};

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