2019-04-21 18:48:33 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2022-02-10 00:15:30 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2019-04-21 18:48:33 +02:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-10-24 19:45:08 +02:00
|
|
|
import { ReactComponent as LockIcon } from '@material-symbols/svg-600/outlined/lock.svg';
|
|
|
|
import { ReactComponent as LockOpenIcon } from '@material-symbols/svg-600/outlined/lock_open.svg';
|
|
|
|
import { ReactComponent as MailIcon } from '@material-symbols/svg-600/outlined/mail.svg';
|
|
|
|
import { ReactComponent as PublicIcon } from '@material-symbols/svg-600/outlined/public.svg';
|
|
|
|
|
2023-10-23 09:43:00 +02:00
|
|
|
import { Button } from 'flavours/glitch/components/button';
|
2023-05-09 03:11:56 +02:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2019-04-21 18:48:33 +02:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
publish: {
|
2022-06-01 05:03:12 +02:00
|
|
|
defaultMessage: 'Publish',
|
2019-04-21 18:48:33 +02:00
|
|
|
id: 'compose_form.publish',
|
|
|
|
},
|
|
|
|
publishLoud: {
|
|
|
|
defaultMessage: '{publish}!',
|
|
|
|
id: 'compose_form.publish_loud',
|
|
|
|
},
|
2022-02-10 00:15:30 +01:00
|
|
|
saveChanges: { id: 'compose_form.save_changes', defaultMessage: 'Save changes' },
|
2023-05-08 15:16:55 +02:00
|
|
|
public: { id: 'privacy.public.short', defaultMessage: 'Public' },
|
|
|
|
unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
|
2023-05-24 12:38:50 +02:00
|
|
|
private: { id: 'privacy.private.short', defaultMessage: 'Followers only' },
|
2023-05-08 15:16:55 +02:00
|
|
|
direct: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
|
2019-04-21 18:48:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
class Publisher extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onSecondarySubmit: PropTypes.func,
|
|
|
|
privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']),
|
|
|
|
sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']),
|
2022-02-10 00:15:30 +01:00
|
|
|
isEditing: PropTypes.bool,
|
2019-04-21 18:48:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
2023-12-18 13:20:08 +01:00
|
|
|
const { disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
|
2019-04-21 18:48:33 +02:00
|
|
|
|
2023-10-24 19:45:08 +02:00
|
|
|
const privacyIcons = {
|
|
|
|
direct: {
|
|
|
|
id: 'envelope',
|
|
|
|
icon: MailIcon,
|
|
|
|
},
|
|
|
|
private: {
|
|
|
|
id: 'lock',
|
|
|
|
icon: LockIcon,
|
|
|
|
},
|
|
|
|
public: {
|
|
|
|
id: 'globe',
|
|
|
|
icon: PublicIcon,
|
|
|
|
},
|
|
|
|
unlisted: {
|
|
|
|
id: 'unlock',
|
|
|
|
icon: LockOpenIcon,
|
|
|
|
},
|
|
|
|
};
|
2022-02-10 00:15:30 +01:00
|
|
|
|
|
|
|
let publishText;
|
|
|
|
if (isEditing) {
|
|
|
|
publishText = intl.formatMessage(messages.saveChanges);
|
|
|
|
} else if (privacy === 'private' || privacy === 'direct') {
|
2023-10-24 19:45:08 +02:00
|
|
|
const icon = privacyIcons[privacy];
|
2022-02-10 00:15:30 +01:00
|
|
|
publishText = (
|
|
|
|
<span>
|
2023-10-24 19:45:08 +02:00
|
|
|
<Icon {...icon} /> {intl.formatMessage(messages.publish)}
|
2022-02-10 00:15:30 +01:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
publishText = privacy !== 'unlisted' ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish);
|
|
|
|
}
|
|
|
|
|
2023-05-08 15:16:55 +02:00
|
|
|
const privacyNames = {
|
|
|
|
public: messages.public,
|
|
|
|
unlisted: messages.unlisted,
|
|
|
|
private: messages.private,
|
|
|
|
direct: messages.direct,
|
|
|
|
};
|
|
|
|
|
2019-04-21 18:48:33 +02:00
|
|
|
return (
|
2023-12-18 13:20:08 +01:00
|
|
|
<div className='compose-form__publish'>
|
|
|
|
{sideArm && !isEditing && sideArm !== 'none' && (
|
2022-11-06 13:30:37 +01:00
|
|
|
<div className='compose-form__publish-button-wrapper'>
|
|
|
|
<Button
|
|
|
|
className='side_arm'
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onSecondarySubmit}
|
|
|
|
style={{ padding: null }}
|
2023-10-24 19:45:08 +02:00
|
|
|
text={<Icon {...privacyIcons[sideArm]} />}
|
2023-05-08 15:16:55 +02:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[sideArm])}`}
|
2022-11-06 13:30:37 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2023-12-18 13:20:08 +01:00
|
|
|
)}
|
2022-11-06 13:30:37 +01:00
|
|
|
<div className='compose-form__publish-button-wrapper'>
|
2019-04-21 18:48:33 +02:00
|
|
|
<Button
|
2022-11-06 13:30:37 +01:00
|
|
|
className='primary'
|
2023-12-22 17:23:15 +01:00
|
|
|
type='submit'
|
2022-11-06 13:30:37 +01:00
|
|
|
text={publishText}
|
2023-05-08 15:16:55 +02:00
|
|
|
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
|
2021-04-04 21:42:30 +02:00
|
|
|
disabled={disabled}
|
2019-04-21 18:48:33 +02:00
|
|
|
/>
|
2022-11-06 13:30:37 +01:00
|
|
|
</div>
|
2019-04-21 18:48:33 +02:00
|
|
|
</div>
|
|
|
|
);
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|
|
|
|
|
2019-04-21 18:48:33 +02:00
|
|
|
}
|
2023-03-24 23:15:25 +01:00
|
|
|
|
|
|
|
export default injectIntl(Publisher);
|