import { useCallback } from 'react'; import { useIntl, defineMessages, FormattedMessage } from 'react-intl'; import { openModal } from 'mastodon/actions/modal'; import { updateNotificationsPolicy } from 'mastodon/actions/notification_policies'; import type { AppDispatch } from 'mastodon/store'; import { useAppSelector, useAppDispatch } from 'mastodon/store'; import { SelectWithLabel } from './select_with_label'; const messages = defineMessages({ accept: { id: 'notifications.policy.accept', defaultMessage: 'Accept' }, accept_hint: { id: 'notifications.policy.accept_hint', defaultMessage: 'Show in notifications', }, filter: { id: 'notifications.policy.filter', defaultMessage: 'Filter' }, filter_hint: { id: 'notifications.policy.filter_hint', defaultMessage: 'Send to filtered notifications inbox', }, drop: { id: 'notifications.policy.drop', defaultMessage: 'Ignore' }, drop_hint: { id: 'notifications.policy.drop_hint', defaultMessage: 'Send to the void, never to be seen again', }, }); // TODO: change the following when we change the API const changeFilter = ( dispatch: AppDispatch, filterType: string, value: string, ) => { if (value === 'drop') { dispatch( openModal({ modalType: 'IGNORE_NOTIFICATIONS', modalProps: { filterType }, }), ); } else { void dispatch(updateNotificationsPolicy({ [filterType]: value })); } }; export const PolicyControls: React.FC = () => { const intl = useIntl(); const dispatch = useAppDispatch(); const notificationPolicy = useAppSelector( (state) => state.notificationPolicy, ); const handleFilterNotFollowing = useCallback( (value: string) => { changeFilter(dispatch, 'for_not_following', value); }, [dispatch], ); const handleFilterNotFollowers = useCallback( (value: string) => { changeFilter(dispatch, 'for_not_followers', value); }, [dispatch], ); const handleFilterNewAccounts = useCallback( (value: string) => { changeFilter(dispatch, 'for_new_accounts', value); }, [dispatch], ); const handleFilterPrivateMentions = useCallback( (value: string) => { changeFilter(dispatch, 'for_private_mentions', value); }, [dispatch], ); const handleFilterLimitedAccounts = useCallback( (value: string) => { changeFilter(dispatch, 'for_limited_accounts', value); }, [dispatch], ); if (!notificationPolicy) return null; const options = [ { value: 'accept', text: intl.formatMessage(messages.accept), meta: intl.formatMessage(messages.accept_hint), }, { value: 'filter', text: intl.formatMessage(messages.filter), meta: intl.formatMessage(messages.filter_hint), }, { value: 'drop', text: intl.formatMessage(messages.drop), meta: intl.formatMessage(messages.drop_hint), }, ]; return (

); };