2021-02-12 19:36:41 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 21:18:23 +09:00
|
|
|
import { PureComponent } from 'react';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2023-11-15 20:01:51 +09:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2024-01-15 06:41:16 +09: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';
|
|
|
|
|
2021-02-12 19:36:41 +09:00
|
|
|
import Dropdown from './dropdown';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
2022-02-09 22:39:12 +09:00
|
|
|
public_short: { id: 'privacy.public.short', defaultMessage: 'Public' },
|
2022-05-03 17:59:23 +09:00
|
|
|
public_long: { id: 'privacy.public.long', defaultMessage: 'Visible for all' },
|
2022-02-09 22:39:12 +09:00
|
|
|
unlisted_short: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
|
2022-05-03 17:59:23 +09:00
|
|
|
unlisted_long: { id: 'privacy.unlisted.long', defaultMessage: 'Visible for all, but opted-out of discovery features' },
|
|
|
|
private_short: { id: 'privacy.private.short', defaultMessage: 'Followers only' },
|
2022-02-09 22:39:12 +09:00
|
|
|
private_long: { id: 'privacy.private.long', defaultMessage: 'Visible for followers only' },
|
2023-05-24 19:38:50 +09:00
|
|
|
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Mentioned people only' },
|
2022-02-09 22:39:12 +09:00
|
|
|
direct_long: { id: 'privacy.direct.long', defaultMessage: 'Visible for mentioned users only' },
|
|
|
|
change_privacy: { id: 'privacy.change', defaultMessage: 'Adjust status privacy' },
|
2021-02-12 19:36:41 +09:00
|
|
|
});
|
|
|
|
|
2023-05-28 21:18:23 +09:00
|
|
|
class PrivacyDropdown extends PureComponent {
|
2021-02-12 19:36:41 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
isUserTouching: PropTypes.func,
|
|
|
|
onModalOpen: PropTypes.func,
|
|
|
|
onModalClose: PropTypes.func,
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
noDirect: PropTypes.bool,
|
|
|
|
container: PropTypes.func,
|
2022-02-13 03:00:33 +09:00
|
|
|
disabled: PropTypes.bool,
|
2021-02-12 19:36:41 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
2022-11-22 19:26:14 +09:00
|
|
|
const { value, onChange, onModalOpen, onModalClose, disabled, noDirect, container, isUserTouching, intl: { formatMessage } } = this.props;
|
2021-02-12 19:36:41 +09:00
|
|
|
|
|
|
|
// We predefine our privacy items so that we can easily pick the
|
|
|
|
// dropdown icon later.
|
|
|
|
const privacyItems = {
|
|
|
|
direct: {
|
|
|
|
icon: 'envelope',
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent: MailIcon,
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.direct_long),
|
2021-02-12 19:36:41 +09:00
|
|
|
name: 'direct',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.direct_short),
|
2021-02-12 19:36:41 +09:00
|
|
|
},
|
|
|
|
private: {
|
|
|
|
icon: 'lock',
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent: LockIcon,
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.private_long),
|
2021-02-12 19:36:41 +09:00
|
|
|
name: 'private',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.private_short),
|
2021-02-12 19:36:41 +09:00
|
|
|
},
|
|
|
|
public: {
|
|
|
|
icon: 'globe',
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent: PublicIcon,
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.public_long),
|
2021-02-12 19:36:41 +09:00
|
|
|
name: 'public',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.public_short),
|
2021-02-12 19:36:41 +09:00
|
|
|
},
|
|
|
|
unlisted: {
|
|
|
|
icon: 'unlock',
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent: LockOpenIcon,
|
2022-02-09 22:39:12 +09:00
|
|
|
meta: formatMessage(messages.unlisted_long),
|
2021-02-12 19:36:41 +09:00
|
|
|
name: 'unlisted',
|
2022-02-09 22:39:12 +09:00
|
|
|
text: formatMessage(messages.unlisted_short),
|
2021-02-12 19:36:41 +09:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-02-11 08:53:12 +09:00
|
|
|
const items = [privacyItems.public, privacyItems.unlisted, privacyItems.private];
|
|
|
|
|
|
|
|
if (!noDirect) {
|
|
|
|
items.push(privacyItems.direct);
|
|
|
|
}
|
2021-02-12 19:36:41 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
disabled={disabled}
|
|
|
|
icon={(privacyItems[value] || {}).icon}
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent={(privacyItems[value] || {}).iconComponent}
|
2021-02-12 19:36:41 +09:00
|
|
|
items={items}
|
|
|
|
onChange={onChange}
|
2022-11-22 19:26:14 +09:00
|
|
|
isUserTouching={isUserTouching}
|
2021-02-12 19:36:41 +09:00
|
|
|
onModalClose={onModalClose}
|
|
|
|
onModalOpen={onModalOpen}
|
2022-02-09 22:39:12 +09:00
|
|
|
title={formatMessage(messages.change_privacy)}
|
2021-02-11 08:53:12 +09:00
|
|
|
container={container}
|
2021-02-12 19:36:41 +09:00
|
|
|
value={value}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 07:15:25 +09:00
|
|
|
|
|
|
|
export default injectIntl(PrivacyDropdown);
|