2017-12-24 08:16:45 +02:00
|
|
|
// Package imports.
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2018-01-06 04:23:06 +02:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2022-02-09 15:39:12 +02:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-12-24 08:16:45 +02:00
|
|
|
import spring from 'react-motion/lib/spring';
|
2022-02-09 15:39:12 +02:00
|
|
|
import Toggle from 'react-toggle';
|
|
|
|
import { connect } from 'react-redux';
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Components.
|
|
|
|
import IconButton from 'flavours/glitch/components/icon_button';
|
2019-08-03 20:10:50 +03:00
|
|
|
import TextIconButton from './text_icon_button';
|
2017-12-24 08:16:45 +02:00
|
|
|
import Dropdown from './dropdown';
|
2021-02-12 12:36:41 +02:00
|
|
|
import PrivacyDropdown from './privacy_dropdown';
|
2022-05-16 12:18:35 +03:00
|
|
|
import LanguageDropdown from '../containers/language_dropdown_container';
|
2019-04-21 18:17:10 +03:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Utils.
|
2022-10-11 11:51:33 +03:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
2022-10-11 11:17:04 +03:00
|
|
|
import { pollLimits } from 'flavours/glitch/initial_state';
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Messages.
|
|
|
|
const messages = defineMessages({
|
|
|
|
advanced_options_icon_title: {
|
|
|
|
defaultMessage: 'Advanced options',
|
|
|
|
id: 'advanced_options.icon_title',
|
|
|
|
},
|
|
|
|
attach: {
|
|
|
|
defaultMessage: 'Attach...',
|
|
|
|
id: 'compose.attach',
|
|
|
|
},
|
2019-02-18 00:53:51 +02:00
|
|
|
content_type: {
|
|
|
|
defaultMessage: 'Content type',
|
|
|
|
id: 'content-type.change',
|
|
|
|
},
|
2017-12-24 08:16:45 +02:00
|
|
|
doodle: {
|
|
|
|
defaultMessage: 'Draw something',
|
|
|
|
id: 'compose.attach.doodle',
|
|
|
|
},
|
2019-02-18 00:53:51 +02:00
|
|
|
html: {
|
|
|
|
defaultMessage: 'HTML',
|
|
|
|
id: 'compose.content-type.html',
|
|
|
|
},
|
2017-12-24 08:16:45 +02:00
|
|
|
local_only_long: {
|
|
|
|
defaultMessage: 'Do not post to other instances',
|
2018-01-06 04:23:06 +02:00
|
|
|
id: 'advanced_options.local-only.long',
|
2017-12-24 08:16:45 +02:00
|
|
|
},
|
|
|
|
local_only_short: {
|
|
|
|
defaultMessage: 'Local-only',
|
2018-01-06 04:23:06 +02:00
|
|
|
id: 'advanced_options.local-only.short',
|
2017-12-24 08:16:45 +02:00
|
|
|
},
|
2019-02-18 00:53:51 +02:00
|
|
|
markdown: {
|
|
|
|
defaultMessage: 'Markdown',
|
|
|
|
id: 'compose.content-type.markdown',
|
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
defaultMessage: 'Plain text',
|
|
|
|
id: 'compose.content-type.plain',
|
|
|
|
},
|
2017-12-24 08:16:45 +02:00
|
|
|
spoiler: {
|
|
|
|
defaultMessage: 'Hide text behind warning',
|
|
|
|
id: 'compose_form.spoiler',
|
|
|
|
},
|
2018-01-06 04:23:06 +02: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 08:16:45 +02:00
|
|
|
upload: {
|
|
|
|
defaultMessage: 'Upload a file',
|
|
|
|
id: 'compose.attach.upload',
|
|
|
|
},
|
2019-03-06 13:30:11 +02: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 08:16:45 +02:00
|
|
|
});
|
|
|
|
|
2022-02-09 15:39:12 +02:00
|
|
|
@connect((state, { name }) => ({ checked: state.getIn(['compose', 'advanced_options', name]) }))
|
|
|
|
class ToggleOption extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
checked: PropTypes.bool,
|
|
|
|
onChangeAdvancedOption: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChange = () => {
|
|
|
|
this.props.onChangeAdvancedOption(this.props.name);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2022-02-09 18:15:36 +02:00
|
|
|
const { meta, text, checked } = this.props;
|
2022-02-09 15:39:12 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<Toggle checked={checked} onChange={this.handleChange} />
|
|
|
|
|
|
|
|
<div className='content'>
|
|
|
|
<strong>{text}</strong>
|
|
|
|
{meta}
|
|
|
|
</div>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:17:10 +03: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-18 00:53:51 +02:00
|
|
|
onChangeContentType: PropTypes.func,
|
2019-04-21 18:17:10 +03:00
|
|
|
onTogglePoll: PropTypes.func,
|
|
|
|
onDoodleOpen: PropTypes.func,
|
|
|
|
onModalClose: PropTypes.func,
|
|
|
|
onModalOpen: PropTypes.func,
|
|
|
|
onToggleSpoiler: PropTypes.func,
|
|
|
|
onUpload: PropTypes.func,
|
|
|
|
privacy: PropTypes.string,
|
2019-02-18 00:53:51 +02:00
|
|
|
contentType: PropTypes.string,
|
2019-04-21 18:17:10 +03:00
|
|
|
resetFileKey: PropTypes.number,
|
|
|
|
spoiler: PropTypes.bool,
|
2019-05-12 22:55:44 +03:00
|
|
|
showContentTypeChoice: PropTypes.bool,
|
2022-02-12 20:00:33 +02:00
|
|
|
isEditing: PropTypes.bool,
|
2019-04-21 18:17:10 +03:00
|
|
|
};
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Handles file selection.
|
2019-04-21 18:17:10 +03:00
|
|
|
handleChangeFiles = ({ target: { files } }) => {
|
2017-12-24 08:16:45 +02:00
|
|
|
const { onUpload } = this.props;
|
|
|
|
if (files.length && onUpload) {
|
|
|
|
onUpload(files);
|
|
|
|
}
|
2019-04-21 18:17:10 +03:00
|
|
|
}
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Handles attachment clicks.
|
2019-04-21 18:17:10 +03:00
|
|
|
handleClickAttach = (name) => {
|
2017-12-24 08:16:45 +02: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 18:17:10 +03:00
|
|
|
}
|
2017-12-24 08:16:45 +02:00
|
|
|
|
|
|
|
// Handles a ref to the file input.
|
2019-04-21 18:17:10 +03:00
|
|
|
handleRefFileElement = (fileElement) => {
|
2017-12-24 08:16:45 +02:00
|
|
|
this.fileElement = fileElement;
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:15:36 +02:00
|
|
|
renderToggleItemContents = (item) => {
|
2022-02-09 15:39:12 +02:00
|
|
|
const { onChangeAdvancedOption } = this.props;
|
|
|
|
const { name, meta, text } = item;
|
|
|
|
|
|
|
|
return <ToggleOption name={name} text={text} meta={meta} onChangeAdvancedOption={onChangeAdvancedOption} />;
|
|
|
|
};
|
|
|
|
|
2017-12-24 08:16:45 +02:00
|
|
|
// Rendering.
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
acceptContentTypes,
|
2018-01-06 04:23:06 +02:00
|
|
|
advancedOptions,
|
2019-02-18 00:53:51 +02:00
|
|
|
contentType,
|
2017-12-24 08:16:45 +02:00
|
|
|
disabled,
|
2019-03-06 13:30:11 +02:00
|
|
|
allowMedia,
|
2017-12-24 08:16:45 +02:00
|
|
|
hasMedia,
|
2019-03-06 13:30:11 +02:00
|
|
|
allowPoll,
|
|
|
|
hasPoll,
|
2018-01-06 04:23:06 +02:00
|
|
|
onChangeAdvancedOption,
|
2019-02-18 00:53:51 +02:00
|
|
|
onChangeContentType,
|
2017-12-24 08:16:45 +02:00
|
|
|
onChangeVisibility,
|
2019-03-06 13:30:11 +02:00
|
|
|
onTogglePoll,
|
2017-12-24 08:16:45 +02:00
|
|
|
onModalClose,
|
|
|
|
onModalOpen,
|
2018-01-03 22:36:21 +02:00
|
|
|
onToggleSpoiler,
|
2017-12-24 08:16:45 +02:00
|
|
|
privacy,
|
|
|
|
resetFileKey,
|
|
|
|
spoiler,
|
2019-05-12 22:55:44 +03:00
|
|
|
showContentTypeChoice,
|
2022-02-12 20:00:33 +02:00
|
|
|
isEditing,
|
2022-02-09 15:39:12 +02:00
|
|
|
intl: { formatMessage },
|
2017-12-24 08:16:45 +02:00
|
|
|
} = this.props;
|
|
|
|
|
2019-02-18 00:53:51 +02:00
|
|
|
const contentTypeItems = {
|
|
|
|
plain: {
|
2019-06-18 17:26:10 +03:00
|
|
|
icon: 'file-text',
|
2019-02-18 00:53:51 +02:00
|
|
|
name: 'text/plain',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.plain),
|
2019-02-18 00:53:51 +02:00
|
|
|
},
|
|
|
|
html: {
|
2019-03-01 12:45:16 +02:00
|
|
|
icon: 'code',
|
2019-02-18 00:53:51 +02:00
|
|
|
name: 'text/html',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.html),
|
2019-02-18 00:53:51 +02:00
|
|
|
},
|
|
|
|
markdown: {
|
2019-03-01 12:45:16 +02:00
|
|
|
icon: 'arrow-circle-down',
|
2019-02-18 00:53:51 +02:00
|
|
|
name: 'text/markdown',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.markdown),
|
2019-02-18 00:53:51 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-12-24 08:16:45 +02:00
|
|
|
// The result.
|
|
|
|
return (
|
|
|
|
<div className='composer--options'>
|
|
|
|
<input
|
|
|
|
accept={acceptContentTypes}
|
2019-03-06 13:30:11 +02:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 08:16:45 +02:00
|
|
|
key={resetFileKey}
|
2019-04-21 18:17:10 +03:00
|
|
|
onChange={this.handleChangeFiles}
|
|
|
|
ref={this.handleRefFileElement}
|
2017-12-24 08:16:45 +02:00
|
|
|
type='file'
|
2019-02-10 22:35:04 +02:00
|
|
|
multiple
|
2019-04-21 18:17:10 +03:00
|
|
|
style={{ display: 'none' }}
|
2017-12-24 08:16:45 +02:00
|
|
|
/>
|
|
|
|
<Dropdown
|
2019-03-06 13:30:11 +02:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 08:16:45 +02:00
|
|
|
icon='paperclip'
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
icon: 'cloud-upload',
|
|
|
|
name: 'upload',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.upload),
|
2017-12-24 08:16:45 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'paint-brush',
|
|
|
|
name: 'doodle',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.doodle),
|
2017-12-24 08:16:45 +02:00
|
|
|
},
|
|
|
|
]}
|
2019-04-21 18:17:10 +03:00
|
|
|
onChange={this.handleClickAttach}
|
2017-12-24 08:16:45 +02:00
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2022-02-09 15:39:12 +02:00
|
|
|
title={formatMessage(messages.attach)}
|
2017-12-24 08:16:45 +02:00
|
|
|
/>
|
2019-03-06 14:42:48 +02:00
|
|
|
{!!pollLimits && (
|
|
|
|
<IconButton
|
|
|
|
active={hasPoll}
|
|
|
|
disabled={disabled || !allowPoll}
|
|
|
|
icon='tasks'
|
|
|
|
inverted
|
|
|
|
onClick={onTogglePoll}
|
|
|
|
size={18}
|
|
|
|
style={{
|
|
|
|
height: null,
|
|
|
|
lineHeight: null,
|
|
|
|
}}
|
2022-02-09 15:39:12 +02:00
|
|
|
title={formatMessage(hasPoll ? messages.remove_poll : messages.add_poll)}
|
2019-03-06 14:42:48 +02:00
|
|
|
/>
|
|
|
|
)}
|
2017-12-24 08:16:45 +02:00
|
|
|
<hr />
|
2021-02-12 12:36:41 +02:00
|
|
|
<PrivacyDropdown
|
2022-02-12 20:00:33 +02:00
|
|
|
disabled={disabled || isEditing}
|
2017-12-24 08:16:45 +02:00
|
|
|
onChange={onChangeVisibility}
|
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
|
|
|
value={privacy}
|
|
|
|
/>
|
2019-05-12 22:55:44 +03:00
|
|
|
{showContentTypeChoice && (
|
|
|
|
<Dropdown
|
|
|
|
disabled={disabled}
|
|
|
|
icon={(contentTypeItems[contentType.split('/')[1]] || {}).icon}
|
|
|
|
items={[
|
|
|
|
contentTypeItems.plain,
|
|
|
|
contentTypeItems.html,
|
|
|
|
contentTypeItems.markdown,
|
|
|
|
]}
|
|
|
|
onChange={onChangeContentType}
|
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2022-02-09 15:39:12 +02:00
|
|
|
title={formatMessage(messages.content_type)}
|
2019-05-12 22:55:44 +03:00
|
|
|
value={contentType}
|
|
|
|
/>
|
|
|
|
)}
|
2018-08-22 16:58:57 +03:00
|
|
|
{onToggleSpoiler && (
|
|
|
|
<TextIconButton
|
|
|
|
active={spoiler}
|
|
|
|
ariaControls='glitch.composer.spoiler.input'
|
|
|
|
label='CW'
|
|
|
|
onClick={onToggleSpoiler}
|
2022-02-09 15:39:12 +02:00
|
|
|
title={formatMessage(messages.spoiler)}
|
2018-08-22 16:58:57 +03:00
|
|
|
/>
|
|
|
|
)}
|
2022-05-16 12:18:35 +03:00
|
|
|
<LanguageDropdown />
|
2018-01-15 00:13:24 +02:00
|
|
|
<Dropdown
|
|
|
|
active={advancedOptions && advancedOptions.some(value => !!value)}
|
2022-02-12 20:00:33 +02:00
|
|
|
disabled={disabled || isEditing}
|
2018-01-15 00:13:24 +02:00
|
|
|
icon='ellipsis-h'
|
|
|
|
items={advancedOptions ? [
|
|
|
|
{
|
2022-02-09 15:39:12 +02:00
|
|
|
meta: formatMessage(messages.local_only_long),
|
2018-01-15 00:13:24 +02:00
|
|
|
name: 'do_not_federate',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.local_only_short),
|
2018-01-15 00:13:24 +02:00
|
|
|
},
|
|
|
|
{
|
2022-02-09 15:39:12 +02:00
|
|
|
meta: formatMessage(messages.threaded_mode_long),
|
2018-01-15 00:13:24 +02:00
|
|
|
name: 'threaded_mode',
|
2022-02-09 15:39:12 +02:00
|
|
|
text: formatMessage(messages.threaded_mode_short),
|
2018-01-15 00:13:24 +02:00
|
|
|
},
|
|
|
|
] : null}
|
|
|
|
onChange={onChangeAdvancedOption}
|
2022-02-09 15:39:12 +02:00
|
|
|
renderItemContents={this.renderToggleItemContents}
|
2018-01-15 00:13:24 +02:00
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2022-02-09 15:39:12 +02:00
|
|
|
title={formatMessage(messages.advanced_options_icon_title)}
|
|
|
|
closeOnChange={false}
|
2018-01-15 00:13:24 +02:00
|
|
|
/>
|
2017-12-24 08:16:45 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|