You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
8.5 KiB
318 lines
8.5 KiB
7 years ago
|
// Package imports.
|
||
|
import PropTypes from 'prop-types';
|
||
|
import React from 'react';
|
||
7 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
3 years ago
|
import { defineMessages, injectIntl } from 'react-intl';
|
||
7 years ago
|
import spring from 'react-motion/lib/spring';
|
||
3 years ago
|
import Toggle from 'react-toggle';
|
||
|
import { connect } from 'react-redux';
|
||
7 years ago
|
|
||
|
// Components.
|
||
|
import IconButton from 'flavours/glitch/components/icon_button';
|
||
5 years ago
|
import TextIconButton from './text_icon_button';
|
||
2 years ago
|
import DropdownContainer from '../containers/dropdown_container';
|
||
|
import PrivacyDropdownContainer from '../containers/privacy_dropdown_container';
|
||
3 years ago
|
import LanguageDropdown from '../containers/language_dropdown_container';
|
||
6 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
7 years ago
|
|
||
|
// Utils.
|
||
2 years ago
|
import Motion from '../../ui/util/optional_motion';
|
||
2 years ago
|
import { pollLimits } from 'flavours/glitch/initial_state';
|
||
7 years ago
|
|
||
|
// Messages.
|
||
|
const messages = defineMessages({
|
||
|
advanced_options_icon_title: {
|
||
|
defaultMessage: 'Advanced options',
|
||
|
id: 'advanced_options.icon_title',
|
||
|
},
|
||
|
attach: {
|
||
|
defaultMessage: 'Attach...',
|
||
|
id: 'compose.attach',
|
||
|
},
|
||
6 years ago
|
content_type: {
|
||
|
defaultMessage: 'Content type',
|
||
|
id: 'content-type.change',
|
||
|
},
|
||
7 years ago
|
doodle: {
|
||
|
defaultMessage: 'Draw something',
|
||
|
id: 'compose.attach.doodle',
|
||
|
},
|
||
6 years ago
|
html: {
|
||
|
defaultMessage: 'HTML',
|
||
|
id: 'compose.content-type.html',
|
||
|
},
|
||
7 years ago
|
local_only_long: {
|
||
|
defaultMessage: 'Do not post to other instances',
|
||
7 years ago
|
id: 'advanced_options.local-only.long',
|
||
7 years ago
|
},
|
||
|
local_only_short: {
|
||
|
defaultMessage: 'Local-only',
|
||
7 years ago
|
id: 'advanced_options.local-only.short',
|
||
7 years ago
|
},
|
||
6 years ago
|
markdown: {
|
||
|
defaultMessage: 'Markdown',
|
||
|
id: 'compose.content-type.markdown',
|
||
|
},
|
||
|
plain: {
|
||
|
defaultMessage: 'Plain text',
|
||
|
id: 'compose.content-type.plain',
|
||
|
},
|
||
7 years ago
|
spoiler: {
|
||
|
defaultMessage: 'Hide text behind warning',
|
||
|
id: 'compose_form.spoiler',
|
||
|
},
|
||
7 years ago
|
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',
|
||
|
},
|
||
7 years ago
|
upload: {
|
||
|
defaultMessage: 'Upload a file',
|
||
|
id: 'compose.attach.upload',
|
||
|
},
|
||
6 years ago
|
add_poll: {
|
||
|
defaultMessage: 'Add a poll',
|
||
|
id: 'poll_button.add_poll',
|
||
|
},
|
||
|
remove_poll: {
|
||
|
defaultMessage: 'Remove poll',
|
||
|
id: 'poll_button.remove_poll',
|
||
|
},
|
||
7 years ago
|
});
|
||
|
|
||
3 years ago
|
@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() {
|
||
3 years ago
|
const { meta, text, checked } = this.props;
|
||
3 years ago
|
|
||
|
return (
|
||
|
<React.Fragment>
|
||
|
<Toggle checked={checked} onChange={this.handleChange} />
|
||
|
|
||
2 years ago
|
<div className='privacy-dropdown__option__content'>
|
||
3 years ago
|
<strong>{text}</strong>
|
||
|
{meta}
|
||
|
</div>
|
||
|
</React.Fragment>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
6 years ago
|
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,
|
||
6 years ago
|
onChangeContentType: PropTypes.func,
|
||
6 years ago
|
onTogglePoll: PropTypes.func,
|
||
|
onDoodleOpen: PropTypes.func,
|
||
|
onToggleSpoiler: PropTypes.func,
|
||
|
onUpload: PropTypes.func,
|
||
6 years ago
|
contentType: PropTypes.string,
|
||
6 years ago
|
resetFileKey: PropTypes.number,
|
||
|
spoiler: PropTypes.bool,
|
||
6 years ago
|
showContentTypeChoice: PropTypes.bool,
|
||
3 years ago
|
isEditing: PropTypes.bool,
|
||
6 years ago
|
};
|
||
7 years ago
|
|
||
|
// Handles file selection.
|
||
6 years ago
|
handleChangeFiles = ({ target: { files } }) => {
|
||
7 years ago
|
const { onUpload } = this.props;
|
||
|
if (files.length && onUpload) {
|
||
|
onUpload(files);
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
// Handles attachment clicks.
|
||
6 years ago
|
handleClickAttach = (name) => {
|
||
7 years ago
|
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;
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
// Handles a ref to the file input.
|
||
6 years ago
|
handleRefFileElement = (fileElement) => {
|
||
7 years ago
|
this.fileElement = fileElement;
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
3 years ago
|
renderToggleItemContents = (item) => {
|
||
3 years ago
|
const { onChangeAdvancedOption } = this.props;
|
||
|
const { name, meta, text } = item;
|
||
|
|
||
|
return <ToggleOption name={name} text={text} meta={meta} onChangeAdvancedOption={onChangeAdvancedOption} />;
|
||
|
};
|
||
|
|
||
7 years ago
|
// Rendering.
|
||
|
render () {
|
||
|
const {
|
||
|
acceptContentTypes,
|
||
7 years ago
|
advancedOptions,
|
||
6 years ago
|
contentType,
|
||
7 years ago
|
disabled,
|
||
6 years ago
|
allowMedia,
|
||
7 years ago
|
hasMedia,
|
||
6 years ago
|
allowPoll,
|
||
|
hasPoll,
|
||
7 years ago
|
onChangeAdvancedOption,
|
||
6 years ago
|
onChangeContentType,
|
||
6 years ago
|
onTogglePoll,
|
||
7 years ago
|
onToggleSpoiler,
|
||
7 years ago
|
resetFileKey,
|
||
|
spoiler,
|
||
6 years ago
|
showContentTypeChoice,
|
||
3 years ago
|
isEditing,
|
||
3 years ago
|
intl: { formatMessage },
|
||
7 years ago
|
} = this.props;
|
||
|
|
||
6 years ago
|
const contentTypeItems = {
|
||
|
plain: {
|
||
5 years ago
|
icon: 'file-text',
|
||
6 years ago
|
name: 'text/plain',
|
||
3 years ago
|
text: formatMessage(messages.plain),
|
||
6 years ago
|
},
|
||
|
html: {
|
||
6 years ago
|
icon: 'code',
|
||
6 years ago
|
name: 'text/html',
|
||
3 years ago
|
text: formatMessage(messages.html),
|
||
6 years ago
|
},
|
||
|
markdown: {
|
||
6 years ago
|
icon: 'arrow-circle-down',
|
||
6 years ago
|
name: 'text/markdown',
|
||
3 years ago
|
text: formatMessage(messages.markdown),
|
||
6 years ago
|
},
|
||
|
};
|
||
|
|
||
7 years ago
|
// The result.
|
||
|
return (
|
||
2 years ago
|
<div className='compose-form__buttons'>
|
||
7 years ago
|
<input
|
||
|
accept={acceptContentTypes}
|
||
6 years ago
|
disabled={disabled || !allowMedia}
|
||
7 years ago
|
key={resetFileKey}
|
||
6 years ago
|
onChange={this.handleChangeFiles}
|
||
|
ref={this.handleRefFileElement}
|
||
7 years ago
|
type='file'
|
||
6 years ago
|
multiple
|
||
6 years ago
|
style={{ display: 'none' }}
|
||
7 years ago
|
/>
|
||
2 years ago
|
<DropdownContainer
|
||
6 years ago
|
disabled={disabled || !allowMedia}
|
||
7 years ago
|
icon='paperclip'
|
||
|
items={[
|
||
|
{
|
||
|
icon: 'cloud-upload',
|
||
|
name: 'upload',
|
||
3 years ago
|
text: formatMessage(messages.upload),
|
||
7 years ago
|
},
|
||
|
{
|
||
|
icon: 'paint-brush',
|
||
|
name: 'doodle',
|
||
3 years ago
|
text: formatMessage(messages.doodle),
|
||
7 years ago
|
},
|
||
|
]}
|
||
6 years ago
|
onChange={this.handleClickAttach}
|
||
3 years ago
|
title={formatMessage(messages.attach)}
|
||
7 years ago
|
/>
|
||
6 years ago
|
{!!pollLimits && (
|
||
|
<IconButton
|
||
|
active={hasPoll}
|
||
|
disabled={disabled || !allowPoll}
|
||
|
icon='tasks'
|
||
|
inverted
|
||
|
onClick={onTogglePoll}
|
||
|
size={18}
|
||
|
style={{
|
||
|
height: null,
|
||
|
lineHeight: null,
|
||
|
}}
|
||
3 years ago
|
title={formatMessage(hasPoll ? messages.remove_poll : messages.add_poll)}
|
||
6 years ago
|
/>
|
||
|
)}
|
||
7 years ago
|
<hr />
|
||
2 years ago
|
<PrivacyDropdownContainer disabled={disabled || isEditing} />
|
||
6 years ago
|
{showContentTypeChoice && (
|
||
2 years ago
|
<DropdownContainer
|
||
6 years ago
|
disabled={disabled}
|
||
|
icon={(contentTypeItems[contentType.split('/')[1]] || {}).icon}
|
||
|
items={[
|
||
|
contentTypeItems.plain,
|
||
|
contentTypeItems.html,
|
||
|
contentTypeItems.markdown,
|
||
|
]}
|
||
|
onChange={onChangeContentType}
|
||
3 years ago
|
title={formatMessage(messages.content_type)}
|
||
6 years ago
|
value={contentType}
|
||
|
/>
|
||
|
)}
|
||
6 years ago
|
{onToggleSpoiler && (
|
||
|
<TextIconButton
|
||
|
active={spoiler}
|
||
|
ariaControls='glitch.composer.spoiler.input'
|
||
|
label='CW'
|
||
|
onClick={onToggleSpoiler}
|
||
3 years ago
|
title={formatMessage(messages.spoiler)}
|
||
6 years ago
|
/>
|
||
|
)}
|
||
3 years ago
|
<LanguageDropdown />
|
||
2 years ago
|
<DropdownContainer
|
||
3 years ago
|
disabled={disabled || isEditing}
|
||
7 years ago
|
icon='ellipsis-h'
|
||
|
items={advancedOptions ? [
|
||
|
{
|
||
3 years ago
|
meta: formatMessage(messages.local_only_long),
|
||
7 years ago
|
name: 'do_not_federate',
|
||
3 years ago
|
text: formatMessage(messages.local_only_short),
|
||
7 years ago
|
},
|
||
|
{
|
||
3 years ago
|
meta: formatMessage(messages.threaded_mode_long),
|
||
7 years ago
|
name: 'threaded_mode',
|
||
3 years ago
|
text: formatMessage(messages.threaded_mode_short),
|
||
7 years ago
|
},
|
||
|
] : null}
|
||
|
onChange={onChangeAdvancedOption}
|
||
3 years ago
|
renderItemContents={this.renderToggleItemContents}
|
||
|
title={formatMessage(messages.advanced_options_icon_title)}
|
||
|
closeOnChange={false}
|
||
7 years ago
|
/>
|
||
7 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|