2017-12-24 15:16:45 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2022-02-09 22:39:12 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2022-02-09 22:39:12 +09:00
|
|
|
import { connect } from 'react-redux';
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2023-05-28 23:38:10 +09:00
|
|
|
import Toggle from 'react-toggle';
|
|
|
|
|
2023-05-09 10:11:56 +09:00
|
|
|
import { IconButton } from 'flavours/glitch/components/icon_button';
|
2023-05-28 23:38:10 +09:00
|
|
|
import { pollLimits } from 'flavours/glitch/initial_state';
|
|
|
|
|
2022-11-22 19:26:14 +09:00
|
|
|
import DropdownContainer from '../containers/dropdown_container';
|
2022-05-16 18:18:35 +09:00
|
|
|
import LanguageDropdown from '../containers/language_dropdown_container';
|
2023-05-28 23:38:10 +09:00
|
|
|
import PrivacyDropdownContainer from '../containers/privacy_dropdown_container';
|
|
|
|
|
|
|
|
import TextIconButton from './text_icon_button';
|
|
|
|
|
2017-12-24 15:16:45 +09:00
|
|
|
const messages = defineMessages({
|
|
|
|
advanced_options_icon_title: {
|
|
|
|
defaultMessage: 'Advanced options',
|
|
|
|
id: 'advanced_options.icon_title',
|
|
|
|
},
|
|
|
|
attach: {
|
|
|
|
defaultMessage: 'Attach...',
|
|
|
|
id: 'compose.attach',
|
|
|
|
},
|
2019-02-18 07:53:51 +09:00
|
|
|
content_type: {
|
|
|
|
defaultMessage: 'Content type',
|
|
|
|
id: 'content-type.change',
|
|
|
|
},
|
2017-12-24 15:16:45 +09:00
|
|
|
doodle: {
|
|
|
|
defaultMessage: 'Draw something',
|
|
|
|
id: 'compose.attach.doodle',
|
|
|
|
},
|
2021-01-19 01:05:19 +09:00
|
|
|
gif: {
|
|
|
|
defaultMessage: 'Embed GIF',
|
|
|
|
id: 'compose.attach.gif',
|
|
|
|
},
|
2019-02-18 07:53:51 +09:00
|
|
|
html: {
|
|
|
|
defaultMessage: 'HTML',
|
|
|
|
id: 'compose.content-type.html',
|
|
|
|
},
|
2017-12-24 15:16:45 +09:00
|
|
|
local_only_long: {
|
|
|
|
defaultMessage: 'Do not post to other instances',
|
2018-01-06 11:23:06 +09:00
|
|
|
id: 'advanced_options.local-only.long',
|
2017-12-24 15:16:45 +09:00
|
|
|
},
|
|
|
|
local_only_short: {
|
|
|
|
defaultMessage: 'Local-only',
|
2018-01-06 11:23:06 +09:00
|
|
|
id: 'advanced_options.local-only.short',
|
2017-12-24 15:16:45 +09:00
|
|
|
},
|
2019-02-18 07:53:51 +09:00
|
|
|
markdown: {
|
|
|
|
defaultMessage: 'Markdown',
|
|
|
|
id: 'compose.content-type.markdown',
|
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
defaultMessage: 'Plain text',
|
|
|
|
id: 'compose.content-type.plain',
|
|
|
|
},
|
2017-12-24 15:16:45 +09:00
|
|
|
spoiler: {
|
|
|
|
defaultMessage: 'Hide text behind warning',
|
|
|
|
id: 'compose_form.spoiler',
|
|
|
|
},
|
2018-01-06 11:23:06 +09: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 15:16:45 +09:00
|
|
|
upload: {
|
|
|
|
defaultMessage: 'Upload a file',
|
|
|
|
id: 'compose.attach.upload',
|
|
|
|
},
|
2019-03-06 20:30:11 +09: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 15:16:45 +09:00
|
|
|
});
|
|
|
|
|
2023-03-25 07:15:25 +09:00
|
|
|
const mapStateToProps = (state, { name }) => ({
|
|
|
|
checked: state.getIn(['compose', 'advanced_options', name]),
|
|
|
|
});
|
|
|
|
|
|
|
|
class ToggleOptionImpl extends ImmutablePureComponent {
|
2022-02-09 22:39:12 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
checked: PropTypes.bool,
|
|
|
|
onChangeAdvancedOption: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChange = () => {
|
|
|
|
this.props.onChangeAdvancedOption(this.props.name);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2022-02-10 01:15:36 +09:00
|
|
|
const { meta, text, checked } = this.props;
|
2022-02-09 22:39:12 +09:00
|
|
|
|
|
|
|
return (
|
2023-05-28 21:56:24 +09:00
|
|
|
<>
|
2022-02-09 22:39:12 +09:00
|
|
|
<Toggle checked={checked} onChange={this.handleChange} />
|
|
|
|
|
2022-11-12 17:59:28 +09:00
|
|
|
<div className='privacy-dropdown__option__content'>
|
2022-02-09 22:39:12 +09:00
|
|
|
<strong>{text}</strong>
|
|
|
|
{meta}
|
|
|
|
</div>
|
2023-05-28 21:56:24 +09:00
|
|
|
</>
|
2022-02-09 22:39:12 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-25 07:15:25 +09:00
|
|
|
const ToggleOption = connect(mapStateToProps)(ToggleOptionImpl);
|
|
|
|
|
2019-04-22 00:17:10 +09:00
|
|
|
class ComposerOptions extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
acceptContentTypes: PropTypes.string,
|
|
|
|
advancedOptions: ImmutablePropTypes.map,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
allowMedia: PropTypes.bool,
|
|
|
|
hasPoll: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2023-12-18 21:20:08 +09:00
|
|
|
onChangeAdvancedOption: PropTypes.func.isRequired,
|
|
|
|
onChangeContentType: PropTypes.func.isRequired,
|
|
|
|
onTogglePoll: PropTypes.func.isRequired,
|
|
|
|
onDoodleOpen: PropTypes.func.isRequired,
|
2023-12-19 09:05:23 +09:00
|
|
|
onEmbedTenor: PropTypes.func.isRequired,
|
|
|
|
onModalClose: PropTypes.func.isRequired,
|
|
|
|
onModalOpen: PropTypes.func.isRequired,
|
2019-04-22 00:17:10 +09:00
|
|
|
onToggleSpoiler: PropTypes.func,
|
2023-12-18 21:20:08 +09:00
|
|
|
onUpload: PropTypes.func.isRequired,
|
2019-02-18 07:53:51 +09:00
|
|
|
contentType: PropTypes.string,
|
2019-04-22 00:17:10 +09:00
|
|
|
resetFileKey: PropTypes.number,
|
|
|
|
spoiler: PropTypes.bool,
|
2019-05-13 04:55:44 +09:00
|
|
|
showContentTypeChoice: PropTypes.bool,
|
2022-02-13 03:00:33 +09:00
|
|
|
isEditing: PropTypes.bool,
|
2019-04-22 00:17:10 +09:00
|
|
|
};
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2019-04-22 00:17:10 +09:00
|
|
|
handleChangeFiles = ({ target: { files } }) => {
|
2017-12-24 15:16:45 +09:00
|
|
|
const { onUpload } = this.props;
|
2023-12-18 21:20:08 +09:00
|
|
|
if (files.length) {
|
2017-12-24 15:16:45 +09:00
|
|
|
onUpload(files);
|
|
|
|
}
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2019-04-22 00:17:10 +09:00
|
|
|
handleClickAttach = (name) => {
|
2017-12-24 15:16:45 +09:00
|
|
|
const { fileElement } = this;
|
2022-04-17 09:04:23 +09:00
|
|
|
const { onDoodleOpen, onEmbedTenor } = this.props;
|
2017-12-24 15:16:45 +09:00
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case 'upload':
|
|
|
|
if (fileElement) {
|
|
|
|
fileElement.click();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case 'doodle':
|
2023-12-18 21:20:08 +09:00
|
|
|
onDoodleOpen();
|
2017-12-24 15:16:45 +09:00
|
|
|
return;
|
2021-01-19 01:05:19 +09:00
|
|
|
case 'gif':
|
2022-04-17 09:04:23 +09:00
|
|
|
if (onEmbedTenor) {
|
|
|
|
onEmbedTenor();
|
2021-01-19 01:05:19 +09:00
|
|
|
}
|
|
|
|
return;
|
2017-12-24 15:16:45 +09:00
|
|
|
}
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2019-04-22 00:17:10 +09:00
|
|
|
handleRefFileElement = (fileElement) => {
|
2017-12-24 15:16:45 +09:00
|
|
|
this.fileElement = fileElement;
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2022-02-10 01:15:36 +09:00
|
|
|
renderToggleItemContents = (item) => {
|
2022-02-09 22:39:12 +09:00
|
|
|
const { onChangeAdvancedOption } = this.props;
|
|
|
|
const { name, meta, text } = item;
|
|
|
|
|
|
|
|
return <ToggleOption name={name} text={text} meta={meta} onChangeAdvancedOption={onChangeAdvancedOption} />;
|
|
|
|
};
|
|
|
|
|
2017-12-24 15:16:45 +09:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
acceptContentTypes,
|
2018-01-06 11:23:06 +09:00
|
|
|
advancedOptions,
|
2019-02-18 07:53:51 +09:00
|
|
|
contentType,
|
2017-12-24 15:16:45 +09:00
|
|
|
disabled,
|
2019-03-06 20:30:11 +09:00
|
|
|
allowMedia,
|
|
|
|
hasPoll,
|
2018-01-06 11:23:06 +09:00
|
|
|
onChangeAdvancedOption,
|
2019-02-18 07:53:51 +09:00
|
|
|
onChangeContentType,
|
2019-03-06 20:30:11 +09:00
|
|
|
onTogglePoll,
|
2018-01-04 05:36:21 +09:00
|
|
|
onToggleSpoiler,
|
2017-12-24 15:16:45 +09:00
|
|
|
resetFileKey,
|
|
|
|
spoiler,
|
2019-05-13 04:55:44 +09:00
|
|
|
showContentTypeChoice,
|
2022-02-13 03:00:33 +09:00
|
|
|
isEditing,
|
2022-02-09 22:39:12 +09:00
|
|
|
intl: { formatMessage },
|
2017-12-24 15:16:45 +09:00
|
|
|
} = this.props;
|
|
|
|
|
2019-02-18 07:53:51 +09:00
|
|
|
const contentTypeItems = {
|
|
|
|
plain: {
|
2019-06-18 23:26:10 +09:00
|
|
|
icon: 'file-text',
|
2019-02-18 07:53:51 +09:00
|
|
|
name: 'text/plain',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.plain),
|
2019-02-18 07:53:51 +09:00
|
|
|
},
|
|
|
|
html: {
|
2019-03-01 19:45:16 +09:00
|
|
|
icon: 'code',
|
2019-02-18 07:53:51 +09:00
|
|
|
name: 'text/html',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.html),
|
2019-02-18 07:53:51 +09:00
|
|
|
},
|
|
|
|
markdown: {
|
2019-03-01 19:45:16 +09:00
|
|
|
icon: 'arrow-circle-down',
|
2019-02-18 07:53:51 +09:00
|
|
|
name: 'text/markdown',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.markdown),
|
2019-02-18 07:53:51 +09:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-12-24 15:16:45 +09:00
|
|
|
// The result.
|
|
|
|
return (
|
2022-11-06 21:30:37 +09:00
|
|
|
<div className='compose-form__buttons'>
|
2017-12-24 15:16:45 +09:00
|
|
|
<input
|
|
|
|
accept={acceptContentTypes}
|
2019-03-06 20:30:11 +09:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 15:16:45 +09:00
|
|
|
key={resetFileKey}
|
2019-04-22 00:17:10 +09:00
|
|
|
onChange={this.handleChangeFiles}
|
|
|
|
ref={this.handleRefFileElement}
|
2017-12-24 15:16:45 +09:00
|
|
|
type='file'
|
2019-02-11 05:35:04 +09:00
|
|
|
multiple
|
2019-04-22 00:17:10 +09:00
|
|
|
style={{ display: 'none' }}
|
2017-12-24 15:16:45 +09:00
|
|
|
/>
|
2022-11-22 19:26:14 +09:00
|
|
|
<DropdownContainer
|
2019-03-06 20:30:11 +09:00
|
|
|
disabled={disabled || !allowMedia}
|
2017-12-24 15:16:45 +09:00
|
|
|
icon='paperclip'
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
icon: 'cloud-upload',
|
|
|
|
name: 'upload',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.upload),
|
2017-12-24 15:16:45 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'paint-brush',
|
|
|
|
name: 'doodle',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.doodle),
|
2017-12-24 15:16:45 +09:00
|
|
|
},
|
2021-01-19 01:05:19 +09:00
|
|
|
{
|
|
|
|
icon: 'file-image-o',
|
|
|
|
name: 'gif',
|
2023-02-17 06:12:09 +09:00
|
|
|
text: formatMessage(messages.gif),
|
2021-01-19 01:05:19 +09:00
|
|
|
}
|
2017-12-24 15:16:45 +09:00
|
|
|
]}
|
2019-04-22 00:17:10 +09:00
|
|
|
onChange={this.handleClickAttach}
|
2022-02-09 22:39:12 +09:00
|
|
|
title={formatMessage(messages.attach)}
|
2017-12-24 15:16:45 +09:00
|
|
|
/>
|
2019-03-06 21:42:48 +09:00
|
|
|
{!!pollLimits && (
|
|
|
|
<IconButton
|
|
|
|
active={hasPoll}
|
2023-11-29 14:33:17 +09:00
|
|
|
disabled={disabled}
|
2019-03-06 21:42:48 +09:00
|
|
|
icon='tasks'
|
|
|
|
inverted
|
|
|
|
onClick={onTogglePoll}
|
|
|
|
size={18}
|
|
|
|
style={{
|
|
|
|
height: null,
|
|
|
|
lineHeight: null,
|
|
|
|
}}
|
2022-02-09 22:39:12 +09:00
|
|
|
title={formatMessage(hasPoll ? messages.remove_poll : messages.add_poll)}
|
2019-03-06 21:42:48 +09:00
|
|
|
/>
|
|
|
|
)}
|
2017-12-24 15:16:45 +09:00
|
|
|
<hr />
|
2022-11-22 19:26:14 +09:00
|
|
|
<PrivacyDropdownContainer disabled={disabled || isEditing} />
|
2019-05-13 04:55:44 +09:00
|
|
|
{showContentTypeChoice && (
|
2022-11-22 19:26:14 +09:00
|
|
|
<DropdownContainer
|
2019-05-13 04:55:44 +09:00
|
|
|
disabled={disabled}
|
|
|
|
icon={(contentTypeItems[contentType.split('/')[1]] || {}).icon}
|
|
|
|
items={[
|
|
|
|
contentTypeItems.plain,
|
|
|
|
contentTypeItems.html,
|
|
|
|
contentTypeItems.markdown,
|
|
|
|
]}
|
|
|
|
onChange={onChangeContentType}
|
2022-02-09 22:39:12 +09:00
|
|
|
title={formatMessage(messages.content_type)}
|
2019-05-13 04:55:44 +09:00
|
|
|
value={contentType}
|
|
|
|
/>
|
|
|
|
)}
|
2018-08-22 22:58:57 +09:00
|
|
|
{onToggleSpoiler && (
|
|
|
|
<TextIconButton
|
|
|
|
active={spoiler}
|
2023-12-18 21:20:08 +09:00
|
|
|
ariaControls='cw-spoiler-input'
|
2018-08-22 22:58:57 +09:00
|
|
|
label='CW'
|
|
|
|
onClick={onToggleSpoiler}
|
2022-02-09 22:39:12 +09:00
|
|
|
title={formatMessage(messages.spoiler)}
|
2018-08-22 22:58:57 +09:00
|
|
|
/>
|
|
|
|
)}
|
2022-05-16 18:18:35 +09:00
|
|
|
<LanguageDropdown />
|
2022-11-22 19:26:14 +09:00
|
|
|
<DropdownContainer
|
2022-02-13 03:00:33 +09:00
|
|
|
disabled={disabled || isEditing}
|
2018-01-15 07:13:24 +09:00
|
|
|
icon='ellipsis-h'
|
|
|
|
items={advancedOptions ? [
|
|
|
|
{
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.local_only_long),
|
2018-01-15 07:13:24 +09:00
|
|
|
name: 'do_not_federate',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.local_only_short),
|
2018-01-15 07:13:24 +09:00
|
|
|
},
|
|
|
|
{
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.threaded_mode_long),
|
2018-01-15 07:13:24 +09:00
|
|
|
name: 'threaded_mode',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.threaded_mode_short),
|
2018-01-15 07:13:24 +09:00
|
|
|
},
|
|
|
|
] : null}
|
|
|
|
onChange={onChangeAdvancedOption}
|
2022-02-09 22:39:12 +09:00
|
|
|
renderItemContents={this.renderToggleItemContents}
|
|
|
|
title={formatMessage(messages.advanced_options_icon_title)}
|
|
|
|
closeOnChange={false}
|
2018-01-15 07:13:24 +09:00
|
|
|
/>
|
2017-12-24 15:16:45 +09:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 07:15:25 +09:00
|
|
|
|
|
|
|
export default injectIntl(ComposerOptions);
|