2019-04-22 01:48:33 +09:00
|
|
|
// Package imports.
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2022-02-10 08:15:30 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-04-22 01:48:33 +09:00
|
|
|
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: {
|
2022-06-01 12:03:12 +09:00
|
|
|
defaultMessage: 'Publish',
|
2019-04-22 01:48:33 +09:00
|
|
|
id: 'compose_form.publish',
|
|
|
|
},
|
|
|
|
publishLoud: {
|
|
|
|
defaultMessage: '{publish}!',
|
|
|
|
id: 'compose_form.publish_loud',
|
|
|
|
},
|
2022-02-10 08:15:30 +09:00
|
|
|
saveChanges: { id: 'compose_form.save_changes', defaultMessage: 'Save changes' },
|
2019-04-22 01:48:33 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
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']),
|
2022-02-10 08:15:30 +09:00
|
|
|
isEditing: PropTypes.bool,
|
2019-04-22 01:48:33 +09:00
|
|
|
};
|
|
|
|
|
2020-02-16 07:51:24 +09:00
|
|
|
handleSubmit = () => {
|
|
|
|
this.props.onSubmit();
|
|
|
|
};
|
|
|
|
|
2019-04-22 01:48:33 +09:00
|
|
|
render () {
|
2022-02-10 08:15:30 +09:00
|
|
|
const { countText, disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
|
2019-04-22 01:48:33 +09:00
|
|
|
|
|
|
|
const diff = maxChars - length(countText || '');
|
|
|
|
const computedClass = classNames('composer--publisher', {
|
2021-04-05 04:42:30 +09:00
|
|
|
disabled: disabled,
|
2019-04-22 01:48:33 +09:00
|
|
|
over: diff < 0,
|
|
|
|
});
|
|
|
|
|
2022-02-10 08:15:30 +09:00
|
|
|
const privacyIcons = { direct: 'envelope', private: 'lock', public: 'globe', unlisted: 'unlock' };
|
|
|
|
|
|
|
|
let publishText;
|
|
|
|
if (isEditing) {
|
|
|
|
publishText = intl.formatMessage(messages.saveChanges);
|
|
|
|
} else if (privacy === 'private' || privacy === 'direct') {
|
|
|
|
const iconId = privacyIcons[privacy];
|
|
|
|
publishText = (
|
|
|
|
<span>
|
|
|
|
<Icon id={iconId} /> {intl.formatMessage(messages.publish)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
publishText = privacy !== 'unlisted' ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish);
|
|
|
|
}
|
|
|
|
|
2019-04-22 01:48:33 +09:00
|
|
|
return (
|
|
|
|
<div className={computedClass}>
|
2022-02-10 08:15:30 +09:00
|
|
|
{sideArm && !isEditing && sideArm !== 'none' ? (
|
2019-04-22 01:48:33 +09:00
|
|
|
<Button
|
|
|
|
className='side_arm'
|
2021-04-05 04:42:30 +09:00
|
|
|
disabled={disabled}
|
2019-04-22 01:48:33 +09:00
|
|
|
onClick={onSecondarySubmit}
|
|
|
|
style={{ padding: null }}
|
2022-02-10 08:15:30 +09:00
|
|
|
text={<Icon id={privacyIcons[sideArm]} />}
|
2019-04-22 01:48:33 +09:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${sideArm}.short` })}`}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<Button
|
|
|
|
className='primary'
|
2022-02-10 08:15:30 +09:00
|
|
|
text={publishText}
|
2019-04-22 01:48:33 +09:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${privacy}.short` })}`}
|
2020-02-16 07:51:24 +09:00
|
|
|
onClick={this.handleSubmit}
|
2021-04-05 04:42:30 +09:00
|
|
|
disabled={disabled}
|
2019-04-22 01:48:33 +09:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|