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