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