// Package imports. import PropTypes from 'prop-types'; import React from 'react'; import { FormattedMessage, defineMessages, } from 'react-intl'; import spring from 'react-motion/lib/spring'; // Components. import IconButton from 'flavours/glitch/components/icon_button'; import TextIconButton from 'flavours/glitch/components/text_icon_button'; import Dropdown from './dropdown'; // Utils. import Motion from 'flavours/glitch/util/optional_motion'; import { assignHandlers, hiddenComponent, } from 'flavours/glitch/util/react_helpers'; // Messages. const messages = defineMessages({ advanced_options_icon_title: { defaultMessage: 'Advanced options', id: 'advanced_options.icon_title', }, attach: { defaultMessage: 'Attach...', id: 'compose.attach', }, change_privacy: { defaultMessage: 'Adjust status privacy', id: 'privacy.change', }, direct_long: { defaultMessage: 'Post to mentioned users only', id: 'privacy.direct.long', }, direct_short: { defaultMessage: 'Direct', id: 'privacy.direct.short', }, doodle: { defaultMessage: 'Draw something', id: 'compose.attach.doodle', }, 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', }, private_long: { defaultMessage: 'Post to followers only', id: 'privacy.private.long', }, private_short: { defaultMessage: 'Followers-only', id: 'privacy.private.short', }, public_long: { defaultMessage: 'Post to public timelines', id: 'privacy.public.long', }, public_short: { defaultMessage: 'Public', id: 'privacy.public.short', }, sensitive: { defaultMessage: 'Mark media as sensitive', id: 'compose_form.sensitive', }, spoiler: { defaultMessage: 'Hide text behind warning', id: 'compose_form.spoiler', }, unlisted_long: { defaultMessage: 'Do not show in public timelines', id: 'privacy.unlisted.long', }, unlisted_short: { defaultMessage: 'Unlisted', id: 'privacy.unlisted.short', }, upload: { defaultMessage: 'Upload a file', id: 'compose.attach.upload', }, }); // Handlers. const handlers = { // 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 } = 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; } }, // Handles a ref to the file input. handleRefFileElement (fileElement) { this.fileElement = fileElement; }, }; // The component. export default class ComposerOptions extends React.PureComponent { // Constructor. constructor (props) { super(props); assignHandlers(this, handlers); // Instance variables. this.fileElement = null; } // Rendering. render () { const { handleChangeFiles, handleClickAttach, handleRefFileElement, } = this.handlers; const { acceptContentTypes, disabled, doNotFederate, full, hasMedia, intl, onChangeSensitivity, onChangeVisibility, onModalClose, onModalOpen, onToggleAdvancedOption, onToggleSpoiler, privacy, resetFileKey, sensitive, spoiler, } = this.props; // We predefine our privacy items so that we can easily pick the // dropdown icon later. const privacyItems = { direct: { icon: 'envelope', meta: , name: 'direct', text: , }, private: { icon: 'lock', meta: , name: 'private', text: , }, public: { icon: 'globe', meta: , name: 'public', text: , }, unlisted: { icon: 'unlock-alt', meta: , name: 'unlisted', text: , }, }; // The result. return (
, }, { icon: 'paint-brush', name: 'doodle', text: , }, ]} onChange={handleClickAttach} onModalClose={onModalClose} onModalOpen={onModalOpen} title={intl.formatMessage(messages.attach)} /> {({ scale }) => (
)}

, name: 'do_not_federate', on: doNotFederate, text: , }, ]} onChange={onToggleAdvancedOption} onModalClose={onModalClose} onModalOpen={onModalOpen} title={intl.formatMessage(messages.advanced_options_icon_title)} />
); } } // Props. ComposerOptions.propTypes = { acceptContentTypes: PropTypes.string, disabled: PropTypes.bool, doNotFederate: PropTypes.bool, full: PropTypes.bool, hasMedia: PropTypes.bool, intl: PropTypes.object.isRequired, onChangeSensitivity: PropTypes.func, onChangeVisibility: PropTypes.func, onDoodleOpen: PropTypes.func, onModalClose: PropTypes.func, onModalOpen: PropTypes.func, onToggleAdvancedOption: PropTypes.func, onToggleSpoiler: PropTypes.func, onUpload: PropTypes.func, privacy: PropTypes.string, resetFileKey: PropTypes.number, sensitive: PropTypes.bool, spoiler: PropTypes.bool, };