1
0
puyopuyotetr.is/app/javascript/flavours/glitch/features/compose/components/publisher.jsx

115 lines
3.6 KiB
React
Raw Normal View History

2019-04-22 01:48:33 +09:00
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
2019-04-22 01:48:33 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import LockIcon from '@material-symbols/svg-600/outlined/lock.svg?react';
import LockOpenIcon from '@material-symbols/svg-600/outlined/lock_open.svg?react';
import MailIcon from '@material-symbols/svg-600/outlined/mail.svg?react';
import PublicIcon from '@material-symbols/svg-600/outlined/public.svg?react';
import { Button } from 'flavours/glitch/components/button';
import { Icon } from 'flavours/glitch/components/icon';
2019-04-22 01:48:33 +09:00
const messages = defineMessages({
publish: {
defaultMessage: 'Publish',
2019-04-22 01:48:33 +09:00
id: 'compose_form.publish',
},
publishLoud: {
defaultMessage: '{publish}!',
id: 'compose_form.publish_loud',
},
saveChanges: { id: 'compose_form.save_changes', defaultMessage: 'Save changes' },
public: { id: 'privacy.public.short', defaultMessage: 'Public' },
unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
private: { id: 'privacy.private.short', defaultMessage: 'Followers only' },
direct: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
2019-04-22 01:48:33 +09: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']),
isEditing: PropTypes.bool,
2019-04-22 01:48:33 +09:00
};
render () {
const { disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;
2019-04-22 01:48:33 +09:00
const privacyIcons = {
direct: {
id: 'envelope',
icon: MailIcon,
},
private: {
id: 'lock',
icon: LockIcon,
},
public: {
id: 'globe',
icon: PublicIcon,
},
unlisted: {
id: 'unlock',
icon: LockOpenIcon,
},
};
let publishText;
if (isEditing) {
publishText = intl.formatMessage(messages.saveChanges);
} else if (privacy === 'private' || privacy === 'direct') {
const icon = privacyIcons[privacy];
publishText = (
<span>
<Icon {...icon} /> {intl.formatMessage(messages.publish)}
</span>
);
} else {
publishText = privacy !== 'unlisted' ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish);
}
const privacyNames = {
public: messages.public,
unlisted: messages.unlisted,
private: messages.private,
direct: messages.direct,
};
2019-04-22 01:48:33 +09:00
return (
<div className='compose-form__publish'>
{sideArm && !isEditing && sideArm !== 'none' && (
<div className='compose-form__publish-button-wrapper'>
<Button
className='side_arm'
disabled={disabled}
onClick={onSecondarySubmit}
style={{ padding: null }}
text={<Icon {...privacyIcons[sideArm]} />}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[sideArm])}`}
/>
</div>
)}
<div className='compose-form__publish-button-wrapper'>
2019-04-22 01:48:33 +09:00
<Button
className='primary'
type='submit'
text={publishText}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
2021-04-05 04:42:30 +09:00
disabled={disabled}
2019-04-22 01:48:33 +09:00
/>
</div>
2019-04-22 01:48:33 +09:00
</div>
);
}
2019-04-22 01:48:33 +09:00
}
export default injectIntl(Publisher);