2017-12-24 07:16:45 +01:00
|
|
|
// Package imports.
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2018-01-06 03:23:06 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-04-21 17:17:10 +02:00
|
|
|
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
|
2017-12-24 07:16:45 +01:00
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
|
|
|
|
// Components.
|
|
|
|
import IconButton from 'flavours/glitch/components/icon_button';
|
2019-08-03 19:10:50 +02:00
|
|
|
import TextIconButton from './text_icon_button';
|
2017-12-24 07:16:45 +01:00
|
|
|
import Dropdown from './dropdown';
|
2019-04-21 17:17:10 +02:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-12-24 07:16:45 +01:00
|
|
|
|
|
|
|
// Utils.
|
|
|
|
import Motion from 'flavours/glitch/util/optional_motion';
|
2019-03-06 13:42:48 +01:00
|
|
|
import { pollLimits } from 'flavours/glitch/util/initial_state';
|
2017-12-24 07:16:45 +01:00
|
|
|
|
|
|
|
// 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',
|
|
|
|
},
|
2019-02-17 23:53:51 +01:00
|
|
|
content_type: {
|
|
|
|
defaultMessage: 'Content type',
|
|
|
|
id: 'content-type.change',
|
|
|
|
},
|
2017-12-24 07:16:45 +01:00
|
|
|
direct_long: {
|
2020-03-08 15:59:55 +01:00
|
|
|
defaultMessage: 'Visible for mentioned users only',
|
2017-12-24 07:16:45 +01:00
|
|
|
id: 'privacy.direct.long',
|
|
|
|
},
|
|
|
|
direct_short: {
|
|
|
|
defaultMessage: 'Direct',
|
|
|
|
id: 'privacy.direct.short',
|
|
|
|
},
|
|
|
|
doodle: {
|
|
|
|
defaultMessage: 'Draw something',
|
|
|
|
id: 'compose.attach.doodle',
|
|
|
|
},
|
2019-02-17 23:53:51 +01:00
|
|
|
html: {
|
|
|
|
defaultMessage: 'HTML',
|
|
|
|
id: 'compose.content-type.html',
|
|
|
|
},
|
2017-12-24 07:16:45 +01:00
|
|
|
local_only_long: {
|
|
|
|
defaultMessage: 'Do not post to other instances',
|
2018-01-06 03:23:06 +01:00
|
|
|
id: 'advanced_options.local-only.long',
|
2017-12-24 07:16:45 +01:00
|
|
|
},
|
|
|
|
local_only_short: {
|
|
|
|
defaultMessage: 'Local-only',
|
2018-01-06 03:23:06 +01:00
|
|
|
id: 'advanced_options.local-only.short',
|
2017-12-24 07:16:45 +01:00
|
|
|
},
|
2019-02-17 23:53:51 +01:00
|
|
|
markdown: {
|
|
|
|
defaultMessage: 'Markdown',
|
|
|
|
id: 'compose.content-type.markdown',
|
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
defaultMessage: 'Plain text',
|
|
|
|
id: 'compose.content-type.plain',
|
|
|
|
},
|
2017-12-24 07:16:45 +01:00
|
|
|
private_long: {
|
2020-03-08 15:59:55 +01:00
|
|
|
defaultMessage: 'Visible for followers only',
|
2017-12-24 07:16:45 +01:00
|
|
|
id: 'privacy.private.long',
|
|
|
|
},
|
|
|
|
private_short: {
|
|
|
|
defaultMessage: 'Followers-only',
|
|
|
|
id: 'privacy.private.short',
|
|
|
|
},
|
|
|
|
public_long: {
|
2020-03-08 15:59:55 +01:00
|
|
|
defaultMessage: 'Visible for all, shown in public timelines',
|
2017-12-24 07:16:45 +01:00
|
|
|
id: 'privacy.public.long',
|
|
|
|
},
|
|
|
|
public_short: {
|
|
|
|
defaultMessage: 'Public',
|
|
|
|
id: 'privacy.public.short',
|
|
|
|
},
|
|
|
|
spoiler: {
|
|
|
|
defaultMessage: 'Hide text behind warning',
|
|
|
|
id: 'compose_form.spoiler',
|
|
|
|
},
|
2018-01-06 03:23:06 +01:00
|
|
|
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',
|
|
|
|
},
|
2017-12-24 07:16:45 +01:00
|
|
|
unlisted_long: {
|
2020-03-08 15:59:55 +01:00
|
|
|
defaultMessage: 'Visible for all, but not in public timelines',
|
2017-12-24 07:16:45 +01:00
|
|
|
id: 'privacy.unlisted.long',
|
|
|
|
},
|
|
|
|
unlisted_short: {
|
|
|
|
defaultMessage: 'Unlisted',
|
|
|
|
id: 'privacy.unlisted.short',
|
|
|
|
},
|
|
|
|
upload: {
|
|
|
|
defaultMessage: 'Upload a file',
|
|
|
|
id: 'compose.attach.upload',
|
|
|
|
},
|
2019-03-06 12:30:11 +01:00
|
|
|
add_poll: {
|
|
|
|
defaultMessage: 'Add a poll',
|
|
|
|
id: 'poll_button.add_poll',
|
|
|
|
},
|
|
|
|
remove_poll: {
|
|
|
|
defaultMessage: 'Remove poll',
|
|
|
|
id: 'poll_button.remove_poll',
|
|
|
|
},
|
2017-12-24 07:16:45 +01:00
|
|
|
});
|
|
|
|
|
2019-04-21 17:17:10 +02:00
|
|
|
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,
|
2019-02-17 23:53:51 +01:00
|
|
|
onChangeContentType: PropTypes.func,
|
2019-04-21 17:17:10 +02:00
|
|
|
onTogglePoll: PropTypes.func,
|
|
|
|
onDoodleOpen: PropTypes.func,
|
|
|
|
onModalClose: PropTypes.func,
|
|
|
|
onModalOpen: PropTypes.func,
|
|
|
|
onToggleSpoiler: PropTypes.func,
|
|
|
|
onUpload: PropTypes.func,
|
|
|
|
privacy: PropTypes.string,
|
2019-02-17 23:53:51 +01:00
|
|
|
contentType: PropTypes.string,
|
2019-04-21 17:17:10 +02:00
|
|
|
resetFileKey: PropTypes.number,
|
|
|
|
spoiler: PropTypes.bool,
|
2019-05-12 21:55:44 +02:00
|
|
|
showContentTypeChoice: PropTypes.bool,
|
2019-04-21 17:17:10 +02:00
|
|
|
};
|
2017-12-24 07:16:45 +01:00
|
|
|
|
|
|
|
// Handles file selection.
|
2019-04-21 17:17:10 +02:00
|
|
|
handleChangeFiles = ({ target: { files } }) => {
|
2017-12-24 07:16:45 +01:00
|
|
|
const { onUpload } = this.props;
|
|
|
|
if (files.length && onUpload) {
|
|
|
|
onUpload(files);
|
|
|
|
}
|
2019-04-21 17:17:10 +02:00
|
|
|
}
|
2017-12-24 07:16:45 +01:00
|
|
|
|
|
|
|
// Handles attachment clicks.
|
2019-04-21 17:17:10 +02:00
|
|
|
handleClickAttach = (name) => {
|
2017-12-24 07:16:45 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-04-21 17:17:10 +02:00
|
|
|
}
|
2017-12-24 07:16:45 +01:00
|
|
|
|
|
|
|
// Handles a ref to the file input.
|
2019-04-21 17:17:10 +02:00
|
|
|
handleRefFileElement = (fileElement) => {
|
2017-12-24 07:16:45 +01:00
|
|
|
this.fileElement = fileElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering.
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
acceptContentTypes,
|
2018-01-06 03:23:06 +01:00
|
|
|
advancedOptions,
|
2019-02-17 23:53:51 +01:00
|
|
|
contentType,
|
2017-12-24 07:16:45 +01:00
|
|
|
disabled,
|
2019-03-06 12:30:11 +01:00
|
|
|
allowMedia,
|
2017-12-24 07:16:45 +01:00
|
|
|
hasMedia,
|
2019-03-06 12:30:11 +01:00
|
|
|
allowPoll,
|
|
|
|
hasPoll,
|
2017-12-24 07:16:45 +01:00
|
|
|
intl,
|
2018-01-06 03:23:06 +01:00
|
|
|
onChangeAdvancedOption,
|
2019-02-17 23:53:51 +01:00
|
|
|
onChangeContentType,
|
2017-12-24 07:16:45 +01:00
|
|
|
onChangeVisibility,
|
2019-03-06 12:30:11 +01:00
|
|
|
onTogglePoll,
|
2017-12-24 07:16:45 +01:00
|
|
|
onModalClose,
|
|
|
|
onModalOpen,
|
2018-01-03 21:36:21 +01:00
|
|
|
onToggleSpoiler,
|
2017-12-24 07:16:45 +01:00
|
|
|
privacy,
|
|
|
|
resetFileKey,
|
|
|
|
spoiler,
|
2019-05-12 21:55:44 +02:00
|
|
|
showContentTypeChoice,
|
2017-12-24 07:16:45 +01:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
// We predefine our privacy items so that we can easily pick the
|
|
|
|
// dropdown icon later.
|
|
|
|
const privacyItems = {
|
|
|
|
direct: {
|
|
|
|
icon: 'envelope',
|
|
|
|
meta: <FormattedMessage {...messages.direct_long} />,
|
|
|
|
name: 'direct',
|
|
|
|
text: <FormattedMessage {...messages.direct_short} />,
|
|
|
|
},
|
|
|
|
private: {
|
|
|
|
icon: 'lock',
|
|
|
|
meta: <FormattedMessage {...messages.private_long} />,
|
|
|
|
name: 'private',
|
|
|
|
text: <FormattedMessage {...messages.private_short} />,
|
|
|
|
},
|
|
|
|
public: {
|
|
|
|
icon: 'globe',
|
|
|
|
meta: <FormattedMessage {...messages.public_long} />,
|
|
|
|
name: 'public',
|
|
|
|
text: <FormattedMessage {...messages.public_short} />,
|
|
|
|
},
|
|
|
|
unlisted: {
|
2019-02-01 16:15:44 +01:00
|
|
|
icon: 'unlock',
|
2017-12-24 07:16:45 +01:00
|
|
|
meta: <FormattedMessage {...messages.unlisted_long} />,
|
|
|
|
name: 'unlisted',
|
|
|
|
text: <FormattedMessage {...messages.unlisted_short} />,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-02-17 23:53:51 +01:00
|
|
|
const contentTypeItems = {
|
|
|
|
plain: {
|
2019-06-18 16:26:10 +02:00
|
|
|
icon: 'file-text',
|
2019-02-17 23:53:51 +01:00
|
|
|
name: 'text/plain',
|
|
|
|
text: <FormattedMessage {...messages.plain} />,
|
|
|
|
},
|
|
|
|
html: {
|
2019-03-01 11:45:16 +01:00
|
|
|
icon: 'code',
|
2019-02-17 23:53:51 +01:00
|
|
|
name: 'text/html',
|
|
|
|
text: <FormattedMessage {...messages.html} />,
|
|
|
|
},
|
|
|
|
markdown: {
|
2019-03-01 11:45:16 +01:00
|
|
|
icon: 'arrow-circle-down',
|
2019-02-17 23:53:51 +01:00
|
|
|
name: 'text/markdown',
|
|
|
|
text: <FormattedMessage {...messages.markdown} />,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-12-24 07:16:45 +01:00
|
|
|
// The result.
|
|
|
|
return (
|
|
|
|
<div className='composer--options'>
|
|
|
|
<input
|
|
|
|
accept={acceptContentTypes}
|
2019-03-06 12:30:11 +01:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 07:16:45 +01:00
|
|
|
key={resetFileKey}
|
2019-04-21 17:17:10 +02:00
|
|
|
onChange={this.handleChangeFiles}
|
|
|
|
ref={this.handleRefFileElement}
|
2017-12-24 07:16:45 +01:00
|
|
|
type='file'
|
2019-02-10 21:35:04 +01:00
|
|
|
multiple
|
2019-04-21 17:17:10 +02:00
|
|
|
style={{ display: 'none' }}
|
2017-12-24 07:16:45 +01:00
|
|
|
/>
|
|
|
|
<Dropdown
|
2019-03-06 12:30:11 +01:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 07:16:45 +01:00
|
|
|
icon='paperclip'
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
icon: 'cloud-upload',
|
|
|
|
name: 'upload',
|
|
|
|
text: <FormattedMessage {...messages.upload} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'paint-brush',
|
|
|
|
name: 'doodle',
|
|
|
|
text: <FormattedMessage {...messages.doodle} />,
|
|
|
|
},
|
|
|
|
]}
|
2019-04-21 17:17:10 +02:00
|
|
|
onChange={this.handleClickAttach}
|
2017-12-24 07:16:45 +01:00
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2018-01-03 21:36:21 +01:00
|
|
|
title={intl.formatMessage(messages.attach)}
|
2017-12-24 07:16:45 +01:00
|
|
|
/>
|
2019-03-06 13:42:48 +01:00
|
|
|
{!!pollLimits && (
|
|
|
|
<IconButton
|
|
|
|
active={hasPoll}
|
|
|
|
disabled={disabled || !allowPoll}
|
|
|
|
icon='tasks'
|
|
|
|
inverted
|
|
|
|
onClick={onTogglePoll}
|
|
|
|
size={18}
|
|
|
|
style={{
|
|
|
|
height: null,
|
|
|
|
lineHeight: null,
|
|
|
|
}}
|
|
|
|
title={intl.formatMessage(hasPoll ? messages.remove_poll : messages.add_poll)}
|
|
|
|
/>
|
|
|
|
)}
|
2017-12-24 07:16:45 +01:00
|
|
|
<hr />
|
|
|
|
<Dropdown
|
|
|
|
disabled={disabled}
|
|
|
|
icon={(privacyItems[privacy] || {}).icon}
|
|
|
|
items={[
|
|
|
|
privacyItems.public,
|
|
|
|
privacyItems.unlisted,
|
|
|
|
privacyItems.private,
|
|
|
|
privacyItems.direct,
|
|
|
|
]}
|
|
|
|
onChange={onChangeVisibility}
|
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
|
|
|
title={intl.formatMessage(messages.change_privacy)}
|
|
|
|
value={privacy}
|
|
|
|
/>
|
2019-05-12 21:55:44 +02:00
|
|
|
{showContentTypeChoice && (
|
|
|
|
<Dropdown
|
|
|
|
disabled={disabled}
|
|
|
|
icon={(contentTypeItems[contentType.split('/')[1]] || {}).icon}
|
|
|
|
items={[
|
|
|
|
contentTypeItems.plain,
|
|
|
|
contentTypeItems.html,
|
|
|
|
contentTypeItems.markdown,
|
|
|
|
]}
|
|
|
|
onChange={onChangeContentType}
|
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
|
|
|
title={intl.formatMessage(messages.content_type)}
|
|
|
|
value={contentType}
|
|
|
|
/>
|
|
|
|
)}
|
2018-08-22 15:58:57 +02:00
|
|
|
{onToggleSpoiler && (
|
|
|
|
<TextIconButton
|
|
|
|
active={spoiler}
|
|
|
|
ariaControls='glitch.composer.spoiler.input'
|
|
|
|
label='CW'
|
|
|
|
onClick={onToggleSpoiler}
|
|
|
|
title={intl.formatMessage(messages.spoiler)}
|
|
|
|
/>
|
|
|
|
)}
|
2018-01-14 23:13:24 +01:00
|
|
|
<Dropdown
|
|
|
|
active={advancedOptions && advancedOptions.some(value => !!value)}
|
|
|
|
disabled={disabled}
|
|
|
|
icon='ellipsis-h'
|
|
|
|
items={advancedOptions ? [
|
|
|
|
{
|
|
|
|
meta: <FormattedMessage {...messages.local_only_long} />,
|
|
|
|
name: 'do_not_federate',
|
|
|
|
on: advancedOptions.get('do_not_federate'),
|
|
|
|
text: <FormattedMessage {...messages.local_only_short} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
meta: <FormattedMessage {...messages.threaded_mode_long} />,
|
|
|
|
name: 'threaded_mode',
|
|
|
|
on: advancedOptions.get('threaded_mode'),
|
|
|
|
text: <FormattedMessage {...messages.threaded_mode_short} />,
|
|
|
|
},
|
|
|
|
] : null}
|
|
|
|
onChange={onChangeAdvancedOption}
|
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
|
|
|
title={intl.formatMessage(messages.advanced_options_icon_title)}
|
|
|
|
/>
|
2017-12-24 07:16:45 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|