2017-12-24 07:16:45 +01:00
|
|
|
// Package imports.
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
defineMessages,
|
|
|
|
FormattedMessage,
|
|
|
|
} from 'react-intl';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
|
|
|
|
// 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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// The component.
|
|
|
|
export default function ComposerPublisher ({
|
|
|
|
countText,
|
|
|
|
disabled,
|
|
|
|
intl,
|
|
|
|
onSecondarySubmit,
|
|
|
|
onSubmit,
|
|
|
|
privacy,
|
|
|
|
sideArm,
|
|
|
|
}) {
|
|
|
|
const diff = maxChars - length(countText || '');
|
|
|
|
const computedClass = classNames('composer--publisher', {
|
|
|
|
disabled: disabled || diff < 0,
|
|
|
|
over: diff < 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
// The result.
|
|
|
|
return (
|
|
|
|
<div className={computedClass}>
|
2018-01-03 21:36:21 +01:00
|
|
|
<span className='count'>{diff}</span>
|
2017-12-24 07:16:45 +01:00
|
|
|
{sideArm && sideArm !== 'none' ? (
|
|
|
|
<Button
|
2017-12-29 23:55:06 +01:00
|
|
|
className='side_arm'
|
2018-01-03 21:36:21 +01:00
|
|
|
disabled={disabled || diff < 0}
|
|
|
|
onClick={onSecondarySubmit}
|
|
|
|
style={{ padding: null }}
|
2017-12-24 07:16:45 +01:00
|
|
|
text={
|
|
|
|
<span>
|
|
|
|
<Icon
|
|
|
|
icon={{
|
|
|
|
public: 'globe',
|
2019-02-01 16:15:44 +01:00
|
|
|
unlisted: 'unlock',
|
2017-12-24 07:16:45 +01:00
|
|
|
private: 'lock',
|
|
|
|
direct: 'envelope',
|
|
|
|
}[sideArm]}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${sideArm}.short` })}`}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<Button
|
2017-12-29 23:55:06 +01:00
|
|
|
className='primary'
|
2017-12-24 07:16:45 +01:00
|
|
|
text={function () {
|
|
|
|
switch (true) {
|
|
|
|
case !!sideArm && sideArm !== 'none':
|
|
|
|
case privacy === 'direct':
|
|
|
|
case privacy === 'private':
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
<Icon
|
|
|
|
icon={{
|
|
|
|
direct: 'envelope',
|
|
|
|
private: 'lock',
|
|
|
|
public: 'globe',
|
2019-02-01 16:15:44 +01:00
|
|
|
unlisted: 'unlock',
|
2017-12-24 07:16:45 +01:00
|
|
|
}[privacy]}
|
|
|
|
/>
|
2018-01-06 06:02:53 +01:00
|
|
|
{' '}
|
2017-12-24 07:16:45 +01:00
|
|
|
<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` })}`}
|
|
|
|
onClick={onSubmit}
|
|
|
|
disabled={disabled || diff < 0}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Props.
|
|
|
|
ComposerPublisher.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']),
|
|
|
|
};
|