import { OrderedSet as ImmutableOrderedSet } from 'immutable'; import React from 'react'; import { FormattedMessage } from 'react-intl'; import { getSettings } from 'soapbox/actions/settings'; import DropdownMenu from 'soapbox/containers/dropdown_menu_container'; import ComposeButton from 'soapbox/features/ui/components/compose-button'; import { useAppSelector, useOwnAccount } from 'soapbox/hooks'; import { getFeatures } from 'soapbox/utils/features'; import SidebarNavigationLink from './sidebar-navigation-link'; import type { Menu } from 'soapbox/components/dropdown_menu'; /** Desktop sidebar with links to different views in the app. */ const SidebarNavigation = () => { const instance = useAppSelector((state) => state.instance); const settings = useAppSelector((state) => getSettings(state)); const account = useOwnAccount(); const notificationCount = useAppSelector((state) => state.notifications.get('unread')); const chatsCount = useAppSelector((state) => state.chats.get('items').reduce((acc: any, curr: any) => acc + Math.min(curr.get('unread', 0), 1), 0)); const followRequestsCount = useAppSelector((state) => state.user_lists.getIn(['follow_requests', 'items'], ImmutableOrderedSet()).count()); const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count()); const features = getFeatures(instance); const makeMenu = (): Menu => { const menu: Menu = []; if (account) { if (account.locked || followRequestsCount > 0) { menu.push({ to: '/follow_requests', text: , icon: require('@tabler/icons/icons/user-plus.svg'), count: followRequestsCount, }); } if (features.bookmarks) { menu.push({ to: '/bookmarks', text: , icon: require('@tabler/icons/icons/bookmark.svg'), }); } if (features.lists) { menu.push({ to: '/lists', text: , icon: require('@tabler/icons/icons/list.svg'), }); } if (settings.get('isDeveloper')) { menu.push({ to: '/developers', icon: require('@tabler/icons/icons/code.svg'), text: , }); } if (account.staff) { menu.push({ to: '/soapbox/admin', icon: require('@tabler/icons/icons/dashboard.svg'), text: , count: dashboardCount, }); } if (features.publicTimeline) { menu.push(null); } } if (features.publicTimeline) { menu.push({ to: '/timeline/local', icon: features.federating ? require('@tabler/icons/icons/users.svg') : require('@tabler/icons/icons/world.svg'), text: features.federating ? instance.title : , }); } if (features.publicTimeline && features.federating) { menu.push({ to: '/timeline/fediverse', icon: require('icons/fediverse.svg'), text: , }); } return menu; }; const menu = makeMenu(); /** Conditionally render the supported messages link */ const renderMessagesLink = (): React.ReactNode => { if (features.chats) { return ( } /> ); } if (features.directTimeline || features.conversations) { return ( } /> ); } return null; }; return (
} /> } /> {account && ( <> } /> {renderMessagesLink()} } /> } /> )} {menu.length > 0 && ( } /> )}
{account && ( )}
); }; export default SidebarNavigation;