import { FormattedMessage } from 'react-intl'; import { createSelector } from '@reduxjs/toolkit'; import { animated, useSpring } from '@react-spring/web'; import { me } from 'mastodon/initial_state'; import { useAppSelector } from 'mastodon/store'; import type { RootState } from 'mastodon/store'; import { HASHTAG_PATTERN_REGEX } from 'mastodon/utils/hashtags'; const selector = createSelector( (state: RootState) => state.compose.get('privacy') as string, (state: RootState) => !!state.accounts.getIn([me, 'locked']), (state: RootState) => state.compose.get('text') as string, (privacy, locked, text) => ({ needsLockWarning: privacy === 'private' && !locked, hashtagWarning: privacy !== 'public' && HASHTAG_PATTERN_REGEX.test(text), directMessageWarning: privacy === 'direct', }), ); export const Warning = () => { const { needsLockWarning, hashtagWarning, directMessageWarning } = useAppSelector(selector); if (needsLockWarning) { return ( ), }} /> ); } if (hashtagWarning) { return ( ); } if (directMessageWarning) { return ( {' '} ); } return null; }; export const WarningMessage: React.FC = ({ children, }) => { const styles = useSpring({ from: { opacity: 0, transform: 'scale(0.85, 0.75)', }, to: { opacity: 1, transform: 'scale(1, 1)', }, }); return ( {children} ); };