2019-04-21 19:48:33 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2022-02-10 01:15:30 +02:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-05-28 17:38:10 +03:00
|
|
|
import { length } from 'stringz';
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
import Button from 'flavours/glitch/components/button';
|
2023-05-09 04:11:56 +03:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2022-10-11 11:17:04 +03:00
|
|
|
import { maxChars } from 'flavours/glitch/initial_state';
|
2019-04-21 19:48:33 +03:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
publish: {
|
2022-06-01 06:03:12 +03:00
|
|
|
defaultMessage: 'Publish',
|
2019-04-21 19:48:33 +03:00
|
|
|
id: 'compose_form.publish',
|
|
|
|
},
|
|
|
|
publishLoud: {
|
|
|
|
defaultMessage: '{publish}!',
|
|
|
|
id: 'compose_form.publish_loud',
|
|
|
|
},
|
2022-02-10 01:15:30 +02:00
|
|
|
saveChanges: { id: 'compose_form.save_changes', defaultMessage: 'Save changes' },
|
2023-05-08 16:16:55 +03:00
|
|
|
public: { id: 'privacy.public.short', defaultMessage: 'Public' },
|
|
|
|
unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
|
2023-05-24 13:38:50 +03:00
|
|
|
private: { id: 'privacy.private.short', defaultMessage: 'Followers only' },
|
2023-05-08 16:16:55 +03:00
|
|
|
direct: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
|
2019-04-21 19:48:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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 01:15:30 +02:00
|
|
|
isEditing: PropTypes.bool,
|
2019-04-21 19:48:33 +03:00
|
|
|
};
|
|
|
|
|
2020-02-16 00:51:24 +02:00
|
|
|
handleSubmit = () => {
|
|
|
|
this.props.onSubmit();
|
|
|
|
};
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
render () {
|
2022-02-10 01:15:30 +02:00
|
|
|
const { countText, disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
|
2019-04-21 19:48:33 +03:00
|
|
|
|
|
|
|
const diff = maxChars - length(countText || '');
|
2022-11-06 14:30:37 +02:00
|
|
|
const computedClass = classNames('compose-form__publish', {
|
2021-04-04 22:42:30 +03:00
|
|
|
disabled: disabled,
|
2019-04-21 19:48:33 +03:00
|
|
|
over: diff < 0,
|
|
|
|
});
|
|
|
|
|
2022-02-10 01:15:30 +02: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);
|
|
|
|
}
|
|
|
|
|
2023-05-08 16:16:55 +03:00
|
|
|
const privacyNames = {
|
|
|
|
public: messages.public,
|
|
|
|
unlisted: messages.unlisted,
|
|
|
|
private: messages.private,
|
|
|
|
direct: messages.direct,
|
|
|
|
};
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
return (
|
|
|
|
<div className={computedClass}>
|
2022-02-10 01:15:30 +02:00
|
|
|
{sideArm && !isEditing && sideArm !== 'none' ? (
|
2022-11-06 14:30:37 +02:00
|
|
|
<div className='compose-form__publish-button-wrapper'>
|
|
|
|
<Button
|
|
|
|
className='side_arm'
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onSecondarySubmit}
|
|
|
|
style={{ padding: null }}
|
|
|
|
text={<Icon id={privacyIcons[sideArm]} />}
|
2023-05-08 16:16:55 +03:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[sideArm])}`}
|
2022-11-06 14:30:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<div className='compose-form__publish-button-wrapper'>
|
2019-04-21 19:48:33 +03:00
|
|
|
<Button
|
2022-11-06 14:30:37 +02:00
|
|
|
className='primary'
|
|
|
|
text={publishText}
|
2023-05-08 16:16:55 +03:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
|
2022-11-06 14:30:37 +02:00
|
|
|
onClick={this.handleSubmit}
|
2021-04-04 22:42:30 +03:00
|
|
|
disabled={disabled}
|
2019-04-21 19:48:33 +03:00
|
|
|
/>
|
2022-11-06 14:30:37 +02:00
|
|
|
</div>
|
2019-04-21 19:48:33 +03:00
|
|
|
</div>
|
|
|
|
);
|
2023-02-03 21:52:07 +02:00
|
|
|
}
|
|
|
|
|
2019-04-21 19:48:33 +03:00
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default injectIntl(Publisher);
|