// Package imports. import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { FormattedMessage, defineMessages, injectIntl } from 'react-intl'; import spring from 'react-motion/lib/spring'; // Components. import IconButton from 'flavours/glitch/components/icon_button'; import TextIconButton from './text_icon_button'; import Dropdown from './dropdown'; import PrivacyDropdown from './privacy_dropdown'; import ImmutablePureComponent from 'react-immutable-pure-component'; // Utils. import Motion from 'flavours/glitch/util/optional_motion'; import { pollLimits } from 'flavours/glitch/util/initial_state'; // Messages. const messages = defineMessages({ advanced_options_icon_title: { defaultMessage: 'Advanced options', id: 'advanced_options.icon_title', }, attach: { defaultMessage: 'Attach...', id: 'compose.attach', }, content_type: { defaultMessage: 'Content type', id: 'content-type.change', }, doodle: { defaultMessage: 'Draw something', id: 'compose.attach.doodle', }, gif: { defaultMessage: 'Embed GIF', id: 'compose.attach.gif', }, jitsi: { defaultMessage: 'Start call', id: 'compose.attach.jitsi', }, html: { defaultMessage: 'HTML', id: 'compose.content-type.html', }, local_only_long: { defaultMessage: 'Do not post to other instances', id: 'advanced_options.local-only.long', }, local_only_short: { defaultMessage: 'Local-only', id: 'advanced_options.local-only.short', }, markdown: { defaultMessage: 'Markdown', id: 'compose.content-type.markdown', }, plain: { defaultMessage: 'Plain text', id: 'compose.content-type.plain', }, spoiler: { defaultMessage: 'Hide text behind warning', id: 'compose_form.spoiler', }, threaded_mode_long: { defaultMessage: 'Automatically opens a reply on posting', id: 'advanced_options.threaded_mode.long', }, threaded_mode_short: { defaultMessage: 'Threaded mode', id: 'advanced_options.threaded_mode.short', }, upload: { defaultMessage: 'Upload a file', id: 'compose.attach.upload', }, add_poll: { defaultMessage: 'Add a poll', id: 'poll_button.add_poll', }, remove_poll: { defaultMessage: 'Remove poll', id: 'poll_button.remove_poll', }, }); export default @injectIntl class ComposerOptions extends ImmutablePureComponent { static propTypes = { acceptContentTypes: PropTypes.string, advancedOptions: ImmutablePropTypes.map, disabled: PropTypes.bool, allowMedia: PropTypes.bool, hasMedia: PropTypes.bool, allowPoll: PropTypes.bool, hasPoll: PropTypes.bool, intl: PropTypes.object.isRequired, onChangeAdvancedOption: PropTypes.func, onChangeVisibility: PropTypes.func, onChangeContentType: PropTypes.func, onTogglePoll: PropTypes.func, onDoodleOpen: PropTypes.func, onEmbedJitsi: PropTypes.func, onEmbedGiphy: PropTypes.func, onModalClose: PropTypes.func, onModalOpen: PropTypes.func, onToggleSpoiler: PropTypes.func, onUpload: PropTypes.func, privacy: PropTypes.string, contentType: PropTypes.string, resetFileKey: PropTypes.number, spoiler: PropTypes.bool, showContentTypeChoice: PropTypes.bool, }; // Handles file selection. handleChangeFiles = ({ target: { files } }) => { const { onUpload } = this.props; if (files.length && onUpload) { onUpload(files); } } // Handles attachment clicks. handleClickAttach = (name) => { const { fileElement } = this; const { onDoodleOpen, onEmbedJitsi, onEmbedGiphy } = this.props; // We switch over the name of the option. switch (name) { case 'upload': if (fileElement) { fileElement.click(); } return; case 'doodle': if (onDoodleOpen) { onDoodleOpen(); } return; case 'jitsi': if (onEmbedJitsi) { onEmbedJitsi(); } return; case 'gif': if (onEmbedGiphy) { onEmbedGiphy(); } return; } } // Handles a ref to the file input. handleRefFileElement = (fileElement) => { this.fileElement = fileElement; } // Rendering. render () { const { acceptContentTypes, advancedOptions, contentType, disabled, allowMedia, hasMedia, allowPoll, hasPoll, intl, onChangeAdvancedOption, onChangeContentType, onChangeVisibility, onTogglePoll, onModalClose, onModalOpen, onToggleSpoiler, privacy, resetFileKey, spoiler, showContentTypeChoice, } = this.props; const contentTypeItems = { plain: { icon: 'file-text', name: 'text/plain', text: , }, html: { icon: 'code', name: 'text/html', text: , }, markdown: { icon: 'arrow-circle-down', name: 'text/markdown', text: , }, }; // The result. return (
, }, { icon: 'paint-brush', name: 'doodle', text: , }, { icon: 'video-camera', name: 'jitsi', text: , }, { icon: 'file-image-o', name: 'gif', text: , } ]} onChange={this.handleClickAttach} onModalClose={onModalClose} onModalOpen={onModalOpen} title={intl.formatMessage(messages.attach)} /> {!!pollLimits && ( )}
{showContentTypeChoice && ( )} {onToggleSpoiler && ( )} !!value)} disabled={disabled} icon='ellipsis-h' items={advancedOptions ? [ { meta: , name: 'do_not_federate', on: advancedOptions.get('do_not_federate'), text: , }, { meta: , name: 'threaded_mode', on: advancedOptions.get('threaded_mode'), text: , }, ] : null} onChange={onChangeAdvancedOption} onModalClose={onModalClose} onModalOpen={onModalOpen} title={intl.formatMessage(messages.advanced_options_icon_title)} />
); } }