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