~cytrogen/masto-fe

ref: b2d67fbe339d4852c97cd332a92a2c32b8835cdb masto-fe/app/javascript/flavours/glitch/features/compose/containers/options_container.js -rw-r--r-- 1.7 KiB
b2d67fbe — Renaud Chaput [Glitch] Improve modals reducer types 2 years ago
                                                                                
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
import { connect } from 'react-redux';

import {
  changeComposeAdvancedOption,
  changeComposeContentType,
  addPoll,
  removePoll,
} from 'flavours/glitch/actions/compose';
import { openModal } from 'flavours/glitch/actions/modal';

import Options from '../components/options';

function mapStateToProps (state) {
  const poll = state.getIn(['compose', 'poll']);
  const media = state.getIn(['compose', 'media_attachments']);
  const pending_media = state.getIn(['compose', 'pending_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 + pending_media < 4 && !media.some(item => ['video', 'audio'].includes(item.get('type'))) : pending_media < 4),
    allowPoll: !(media && !!media.size),
    showContentTypeChoice: state.getIn(['local_settings', 'show_content_type_choice']),
    contentType: state.getIn(['compose', 'content_type']),
  };
}

const mapDispatchToProps = (dispatch) => ({

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

  onChangeContentType(value) {
    dispatch(changeComposeContentType(value));
  },

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

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

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