about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/compose/containers/options_container.js
blob: e846cfbd5f1e4269e10de10d420a455e85646c46 (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
import { connect } from 'react-redux';
import Options from '../components/options';
import {
  changeComposeAdvancedOption,
  changeComposeSensitivity,
} from 'flavours/glitch/actions/compose';
import { addPoll, removePoll } from 'flavours/glitch/actions/compose';
import { closeModal, openModal } from 'flavours/glitch/actions/modal';

function mapStateToProps (state) {
  const spoilersAlwaysOn = state.getIn(['local_settings', 'always_show_spoilers_field']);
  const poll = state.getIn(['compose', 'poll']);
  const media = state.getIn(['compose', 'media_attachments']);
  return {
    acceptContentTypes: state.getIn(['media_attachments', 'accept_content_types']).toArray().join(','),
    resetFileKey: state.getIn(['compose', 'resetFileKey']),
    hasPoll: !!poll,
    allowMedia: !poll && (media ? media.size < 4 && !media.some(item => item.get('type') === 'video') : true),
    hasMedia: media && !!media.size,
    allowPoll: !(media && !!media.size),
  };
};

const mapDispatchToProps = (dispatch) => ({

  onChangeAdvancedOption(option, value) {
    dispatch(changeComposeAdvancedOption(option, value));
  },

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

  onTogglePoll() {
    dispatch((_, getState) => {
      if (getState().getIn(['compose', 'poll'])) {
        dispatch(removePoll());
      } else {
        dispatch(addPoll());
      }
    });
  },

  onDoodleOpen() {
    dispatch(openModal('DOODLE', { noEsc: true }));
  },

  onModalClose() {
    dispatch(closeModal());
  },

  onModalOpen(props) {
    dispatch(openModal('ACTIONS', props));
  },
});

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