2019-04-21 19:48:33 +03:00
|
|
|
// Package imports.
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
|
|
|
// Components.
|
|
|
|
import Button from 'flavours/glitch/components/button';
|
|
|
|
import Icon from 'flavours/glitch/components/icon';
|
|
|
|
|
|
|
|
// Utils.
|
|
|
|
import { maxChars } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
|
|
|
// Messages.
|
|
|
|
const messages = defineMessages({
|
|
|
|
publish: {
|
|
|
|
defaultMessage: 'Toot',
|
|
|
|
id: 'compose_form.publish',
|
|
|
|
},
|
|
|
|
publishLoud: {
|
|
|
|
defaultMessage: '{publish}!',
|
|
|
|
id: 'compose_form.publish_loud',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default @injectIntl
|
|
|
|
class Publisher extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
countText: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onSecondarySubmit: PropTypes.func,
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']),
|
|
|
|
sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']),
|
|
|
|
};
|
|
|
|
|
2020-02-16 00:51:24 +02:00
|
|
|
handleSubmit = () => {
|
|
|
|
this.props.onSubmit();
|
|
|
|
};
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
render () {
|
2020-02-16 00:51:24 +02:00
|
|
|
const { countText, disabled, intl, onSecondarySubmit, privacy, sideArm } = this.props;
|
2019-04-21 19:48:33 +03:00
|
|
|
|
|
|
|
const diff = maxChars - length(countText || '');
|
|
|
|
const computedClass = classNames('composer--publisher', {
|
2021-04-04 22:42:30 +03:00
|
|
|
disabled: disabled,
|
2019-04-21 19:48:33 +03:00
|
|
|
over: diff < 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={computedClass}>
|
|
|
|
{sideArm && sideArm !== 'none' ? (
|
|
|
|
<Button
|
|
|
|
className='side_arm'
|
2021-04-04 22:42:30 +03:00
|
|
|
disabled={disabled}
|
2019-04-21 19:48:33 +03:00
|
|
|
onClick={onSecondarySubmit}
|
|
|
|
style={{ padding: null }}
|
|
|
|
text={
|
|
|
|
<span>
|
|
|
|
<Icon
|
2019-09-09 16:28:45 +03:00
|
|
|
id={{
|
2019-04-21 19:48:33 +03:00
|
|
|
public: 'globe',
|
|
|
|
unlisted: 'unlock',
|
|
|
|
private: 'lock',
|
|
|
|
direct: 'envelope',
|
|
|
|
}[sideArm]}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${sideArm}.short` })}`}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<Button
|
|
|
|
className='primary'
|
|
|
|
text={function () {
|
|
|
|
switch (true) {
|
|
|
|
case !!sideArm && sideArm !== 'none':
|
|
|
|
case privacy === 'direct':
|
|
|
|
case privacy === 'private':
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
<Icon
|
2019-09-09 16:28:45 +03:00
|
|
|
id={{
|
2019-04-21 19:48:33 +03:00
|
|
|
direct: 'envelope',
|
|
|
|
private: 'lock',
|
|
|
|
public: 'globe',
|
|
|
|
unlisted: 'unlock',
|
|
|
|
}[privacy]}
|
|
|
|
/>
|
|
|
|
{' '}
|
|
|
|
<FormattedMessage {...messages.publish} />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
case privacy === 'public':
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
<FormattedMessage
|
|
|
|
{...messages.publishLoud}
|
|
|
|
values={{ publish: <FormattedMessage {...messages.publish} /> }}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return <span><FormattedMessage {...messages.publish} /></span>;
|
|
|
|
}
|
|
|
|
}()}
|
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${privacy}.short` })}`}
|
2020-02-16 00:51:24 +02:00
|
|
|
onClick={this.handleSubmit}
|
2021-04-04 22:42:30 +03:00
|
|
|
disabled={disabled}
|
2019-04-21 19:48:33 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|