import { useCallback, useEffect } from 'react'; import { useIntl, defineMessages, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { NavLink, useRouteMatch } from 'react-router-dom'; import AddIcon from '@/material-icons/400-24px/add.svg?react'; import HomeActiveIcon from '@/material-icons/400-24px/home-fill.svg?react'; import HomeIcon from '@/material-icons/400-24px/home.svg?react'; import MenuIcon from '@/material-icons/400-24px/menu.svg?react'; import NotificationsActiveIcon from '@/material-icons/400-24px/notifications-fill.svg?react'; import NotificationsIcon from '@/material-icons/400-24px/notifications.svg?react'; import SearchIcon from '@/material-icons/400-24px/search.svg?react'; import { openModal } from 'mastodon/actions/modal'; import { toggleNavigation } from 'mastodon/actions/navigation'; import { fetchServer } from 'mastodon/actions/server'; import { Icon } from 'mastodon/components/icon'; import { IconWithBadge } from 'mastodon/components/icon_with_badge'; import { useIdentity } from 'mastodon/identity_context'; import { registrationsOpen, sso_redirect } from 'mastodon/initial_state'; import { selectUnreadNotificationGroupsCount } from 'mastodon/selectors/notifications'; import { useAppDispatch, useAppSelector } from 'mastodon/store'; const messages = defineMessages({ home: { id: 'tabs_bar.home', defaultMessage: 'Home' }, search: { id: 'tabs_bar.search', defaultMessage: 'Search' }, publish: { id: 'tabs_bar.publish', defaultMessage: 'New Post' }, notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications', }, menu: { id: 'tabs_bar.menu', defaultMessage: 'Menu' }, }); const IconLabelButton: React.FC<{ to: string; icon?: React.ReactNode; activeIcon?: React.ReactNode; title: string; }> = ({ to, icon, activeIcon, title }) => { const match = useRouteMatch(to); return ( {match && activeIcon ? activeIcon : icon} ); }; const NotificationsButton = () => { const count = useAppSelector(selectUnreadNotificationGroupsCount); const intl = useIntl(); return ( } activeIcon={ } title={intl.formatMessage(messages.notifications)} /> ); }; const LoginOrSignUp: React.FC = () => { const dispatch = useAppDispatch(); const signupUrl = useAppSelector( (state) => (state.server.getIn(['server', 'registrations', 'url'], null) as | string | null) ?? '/auth/sign_up', ); const openClosedRegistrationsModal = useCallback(() => { dispatch(openModal({ modalType: 'CLOSED_REGISTRATIONS', modalProps: {} })); }, [dispatch]); useEffect(() => { dispatch(fetchServer()); }, [dispatch]); if (sso_redirect) { return (
); } else { let signupButton; if (registrationsOpen) { signupButton = ( ); } else { signupButton = ( ); } return (
{signupButton}
); } }; export const NavigationBar: React.FC = () => { const { signedIn } = useIdentity(); const dispatch = useAppDispatch(); const open = useAppSelector((state) => state.navigation.open); const intl = useIntl(); const handleClick = useCallback(() => { dispatch(toggleNavigation()); }, [dispatch]); return (
{!signedIn && }
{signedIn && ( <> } activeIcon={} /> } /> } /> )}
); };