glitchier-soc/app/javascript/flavours/glitch/features/compose/containers/options_container.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-04-21 19:31:26 +03:00
import { connect } from 'react-redux';
2019-04-21 19:31:26 +03:00
import {
changeComposeAdvancedOption,
changeComposeContentType,
addPoll,
removePoll,
2019-04-21 19:31:26 +03:00
} from 'flavours/glitch/actions/compose';
import { openModal } from 'flavours/glitch/actions/modal';
2019-04-21 19:31:26 +03:00
import Options from '../components/options';
2019-04-21 19:31:26 +03:00
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']);
2019-04-21 19:31:26 +03:00
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),
2019-04-21 19:31:26 +03:00
allowPoll: !(media && !!media.size),
2019-05-12 22:55:44 +03:00
showContentTypeChoice: state.getIn(['local_settings', 'show_content_type_choice']),
contentType: state.getIn(['compose', 'content_type']),
2019-04-21 19:31:26 +03:00
};
}
2019-04-21 19:31:26 +03:00
const mapDispatchToProps = (dispatch) => ({
onChangeAdvancedOption(option, value) {
dispatch(changeComposeAdvancedOption(option, value));
},
onChangeContentType(value) {
dispatch(changeComposeContentType(value));
},
2019-04-21 19:31:26 +03:00
onTogglePoll() {
dispatch((_, getState) => {
if (getState().getIn(['compose', 'poll'])) {
dispatch(removePoll());
} else {
dispatch(addPoll());
}
});
},
onDoodleOpen() {
dispatch(openModal({
modalType: 'DOODLE',
modalProps: { noEsc: true, noClose: true },
}));
2019-04-21 19:31:26 +03:00
},
});
export default connect(mapStateToProps, mapDispatchToProps)(Options);