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';
|
2017-12-24 08:16:45 +02:00
|
|
|
import {
|
|
|
|
FormattedMessage,
|
|
|
|
defineMessages,
|
|
|
|
} from 'react-intl';
|
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
|
|
|
|
// Components.
|
|
|
|
import IconButton from 'flavours/glitch/components/icon_button';
|
|
|
|
import TextIconButton from 'flavours/glitch/components/text_icon_button';
|
|
|
|
import Dropdown from './dropdown';
|
|
|
|
|
|
|
|
// Utils.
|
|
|
|
import Motion from 'flavours/glitch/util/optional_motion';
|
|
|
|
import {
|
|
|
|
assignHandlers,
|
|
|
|
hiddenComponent,
|
|
|
|
} from 'flavours/glitch/util/react_helpers';
|
|
|
|
|
|
|
|
// 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',
|
|
|
|
},
|
|
|
|
direct_long: {
|
|
|
|
defaultMessage: 'Post to mentioned users only',
|
|
|
|
id: 'privacy.direct.long',
|
|
|
|
},
|
|
|
|
direct_short: {
|
|
|
|
defaultMessage: 'Direct',
|
|
|
|
id: 'privacy.direct.short',
|
|
|
|
},
|
|
|
|
doodle: {
|
|
|
|
defaultMessage: 'Draw something',
|
|
|
|
id: 'compose.attach.doodle',
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
private_long: {
|
|
|
|
defaultMessage: 'Post to followers only',
|
|
|
|
id: 'privacy.private.long',
|
|
|
|
},
|
|
|
|
private_short: {
|
|
|
|
defaultMessage: 'Followers-only',
|
|
|
|
id: 'privacy.private.short',
|
|
|
|
},
|
|
|
|
public_long: {
|
|
|
|
defaultMessage: 'Post to public timelines',
|
|
|
|
id: 'privacy.public.long',
|
|
|
|
},
|
|
|
|
public_short: {
|
|
|
|
defaultMessage: 'Public',
|
|
|
|
id: 'privacy.public.short',
|
|
|
|
},
|
|
|
|
sensitive: {
|
|
|
|
defaultMessage: 'Mark media as sensitive',
|
|
|
|
id: 'compose_form.sensitive',
|
|
|
|
},
|
|
|
|
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
|
|
|
unlisted_long: {
|
|
|
|
defaultMessage: 'Do not show in public timelines',
|
|
|
|
id: 'privacy.unlisted.long',
|
|
|
|
},
|
|
|
|
unlisted_short: {
|
|
|
|
defaultMessage: 'Unlisted',
|
|
|
|
id: 'privacy.unlisted.short',
|
|
|
|
},
|
|
|
|
upload: {
|
|
|
|
defaultMessage: 'Upload a file',
|
|
|
|
id: 'compose.attach.upload',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
const handlers = {
|
|
|
|
|
|
|
|
// Handles file selection.
|
2018-01-03 22:36:21 +02:00
|
|
|
handleChangeFiles ({ target: { files } }) {
|
2017-12-24 08:16:45 +02:00
|
|
|
const { onUpload } = this.props;
|
|
|
|
if (files.length && onUpload) {
|
|
|
|
onUpload(files);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Handles attachment clicks.
|
2018-01-03 22:36:21 +02: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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Handles a ref to the file input.
|
2018-01-03 22:36:21 +02:00
|
|
|
handleRefFileElement (fileElement) {
|
2017-12-24 08:16:45 +02:00
|
|
|
this.fileElement = fileElement;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// The component.
|
|
|
|
export default class ComposerOptions extends React.PureComponent {
|
|
|
|
|
|
|
|
// Constructor.
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
assignHandlers(this, handlers);
|
|
|
|
|
|
|
|
// Instance variables.
|
|
|
|
this.fileElement = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering.
|
|
|
|
render () {
|
|
|
|
const {
|
2018-01-03 22:36:21 +02:00
|
|
|
handleChangeFiles,
|
|
|
|
handleClickAttach,
|
|
|
|
handleRefFileElement,
|
2017-12-24 08:16:45 +02:00
|
|
|
} = this.handlers;
|
|
|
|
const {
|
|
|
|
acceptContentTypes,
|
2018-01-06 04:23:06 +02:00
|
|
|
advancedOptions,
|
2017-12-24 08:16:45 +02:00
|
|
|
disabled,
|
|
|
|
full,
|
|
|
|
hasMedia,
|
|
|
|
intl,
|
2018-01-06 04:23:06 +02:00
|
|
|
onChangeAdvancedOption,
|
2017-12-24 08:16:45 +02:00
|
|
|
onChangeSensitivity,
|
|
|
|
onChangeVisibility,
|
|
|
|
onModalClose,
|
|
|
|
onModalOpen,
|
2018-01-03 22:36:21 +02:00
|
|
|
onToggleSpoiler,
|
2017-12-24 08:16:45 +02:00
|
|
|
privacy,
|
|
|
|
resetFileKey,
|
|
|
|
sensitive,
|
|
|
|
spoiler,
|
|
|
|
} = 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: {
|
|
|
|
icon: 'unlock-alt',
|
|
|
|
meta: <FormattedMessage {...messages.unlisted_long} />,
|
|
|
|
name: 'unlisted',
|
|
|
|
text: <FormattedMessage {...messages.unlisted_short} />,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// The result.
|
|
|
|
return (
|
|
|
|
<div className='composer--options'>
|
|
|
|
<input
|
|
|
|
accept={acceptContentTypes}
|
|
|
|
disabled={disabled || full}
|
|
|
|
key={resetFileKey}
|
2018-01-03 22:36:21 +02:00
|
|
|
onChange={handleChangeFiles}
|
|
|
|
ref={handleRefFileElement}
|
2017-12-24 08:16:45 +02:00
|
|
|
type='file'
|
|
|
|
{...hiddenComponent}
|
|
|
|
/>
|
|
|
|
<Dropdown
|
|
|
|
disabled={disabled || full}
|
|
|
|
icon='paperclip'
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
icon: 'cloud-upload',
|
|
|
|
name: 'upload',
|
|
|
|
text: <FormattedMessage {...messages.upload} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'paint-brush',
|
|
|
|
name: 'doodle',
|
|
|
|
text: <FormattedMessage {...messages.doodle} />,
|
|
|
|
},
|
|
|
|
]}
|
2018-01-03 22:36:21 +02:00
|
|
|
onChange={handleClickAttach}
|
2017-12-24 08:16:45 +02:00
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2018-01-03 22:36:21 +02:00
|
|
|
title={intl.formatMessage(messages.attach)}
|
2017-12-24 08:16:45 +02:00
|
|
|
/>
|
|
|
|
<Motion
|
|
|
|
defaultStyle={{ scale: 0.87 }}
|
|
|
|
style={{
|
|
|
|
scale: spring(hasMedia ? 1 : 0.87, {
|
|
|
|
stiffness: 200,
|
|
|
|
damping: 3,
|
|
|
|
}),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{({ scale }) => (
|
2017-12-30 00:55:06 +02:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: hasMedia ? null : 'none',
|
|
|
|
transform: `scale(${scale})`,
|
|
|
|
}}
|
|
|
|
>
|
2017-12-24 08:16:45 +02:00
|
|
|
<IconButton
|
|
|
|
active={sensitive}
|
|
|
|
className='sensitive'
|
|
|
|
disabled={spoiler}
|
|
|
|
icon={sensitive ? 'eye-slash' : 'eye'}
|
|
|
|
inverted
|
|
|
|
onClick={onChangeSensitivity}
|
|
|
|
size={18}
|
|
|
|
style={{
|
|
|
|
height: null,
|
|
|
|
lineHeight: null,
|
|
|
|
}}
|
|
|
|
title={intl.formatMessage(messages.sensitive)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
<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}
|
|
|
|
/>
|
2018-08-22 16:58:57 +03:00
|
|
|
{onToggleSpoiler && (
|
|
|
|
<TextIconButton
|
|
|
|
active={spoiler}
|
|
|
|
ariaControls='glitch.composer.spoiler.input'
|
|
|
|
label='CW'
|
|
|
|
onClick={onToggleSpoiler}
|
|
|
|
title={intl.formatMessage(messages.spoiler)}
|
|
|
|
/>
|
|
|
|
)}
|
2018-01-15 00:13:24 +02: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 08:16:45 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Props.
|
|
|
|
ComposerOptions.propTypes = {
|
|
|
|
acceptContentTypes: PropTypes.string,
|
2018-01-06 04:23:06 +02:00
|
|
|
advancedOptions: ImmutablePropTypes.map,
|
2017-12-24 08:16:45 +02:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
full: PropTypes.bool,
|
|
|
|
hasMedia: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2018-01-06 04:23:06 +02:00
|
|
|
onChangeAdvancedOption: PropTypes.func,
|
2017-12-24 08:16:45 +02:00
|
|
|
onChangeSensitivity: PropTypes.func,
|
|
|
|
onChangeVisibility: PropTypes.func,
|
|
|
|
onDoodleOpen: PropTypes.func,
|
|
|
|
onModalClose: PropTypes.func,
|
|
|
|
onModalOpen: PropTypes.func,
|
2018-01-03 22:36:21 +02:00
|
|
|
onToggleSpoiler: PropTypes.func,
|
2017-12-24 08:16:45 +02:00
|
|
|
onUpload: PropTypes.func,
|
|
|
|
privacy: PropTypes.string,
|
2018-01-03 22:36:21 +02:00
|
|
|
resetFileKey: PropTypes.number,
|
2017-12-24 08:16:45 +02:00
|
|
|
sensitive: PropTypes.bool,
|
|
|
|
spoiler: PropTypes.bool,
|
|
|
|
};
|