bigbuffet-rw/app/soapbox/components/sidebar-navigation.tsx

194 lines
6.3 KiB
TypeScript
Raw Normal View History

import { OrderedSet as ImmutableOrderedSet } from 'immutable';
2022-03-21 11:09:01 -07:00
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { getSettings } from 'soapbox/actions/settings';
import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
2022-03-21 11:09:01 -07:00
import ComposeButton from 'soapbox/features/ui/components/compose-button';
import { useAppSelector, useOwnAccount } from 'soapbox/hooks';
2022-03-21 11:09:01 -07:00
import { getBaseURL } from 'soapbox/utils/accounts';
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. */
2022-03-21 11:09:01 -07:00
const SidebarNavigation = () => {
const instance = useAppSelector((state) => state.instance);
const settings = useAppSelector((state) => getSettings(state));
const account = useOwnAccount();
2022-03-21 11:09:01 -07:00
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());
2022-04-28 14:20:21 -07:00
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
2022-03-21 11:09:01 -07:00
2022-04-24 12:28:07 -07:00
const baseURL = account ? getBaseURL(account) : '';
2022-03-21 11:09:01 -07:00
const features = getFeatures(instance);
const makeMenu = (): Menu => {
const menu: Menu = [];
if (account) {
if (account.locked || followRequestsCount > 0) {
menu.push({
to: '/follow_requests',
text: <FormattedMessage id='navigation_bar.follow_requests' defaultMessage='Follow requests' />,
icon: require('@tabler/icons/icons/user-plus.svg'),
count: followRequestsCount,
});
}
if (features.bookmarks) {
menu.push({
to: '/bookmarks',
text: <FormattedMessage id='column.bookmarks' defaultMessage='Bookmarks' />,
icon: require('@tabler/icons/icons/bookmark.svg'),
});
}
if (features.lists) {
menu.push({
to: '/lists',
text: <FormattedMessage id='column.lists' defaultMessage='Lists' />,
icon: require('@tabler/icons/icons/list.svg'),
});
}
if (instance.invites_enabled) {
menu.push({
to: `${baseURL}/invites`,
icon: require('@tabler/icons/icons/mailbox.svg'),
text: <FormattedMessage id='navigation.invites' defaultMessage='Invites' />,
});
}
if (settings.get('isDeveloper')) {
menu.push({
to: '/developers',
icon: require('@tabler/icons/icons/code.svg'),
text: <FormattedMessage id='navigation.developers' defaultMessage='Developers' />,
});
}
if (account.staff) {
menu.push({
2022-04-30 09:31:04 -07:00
to: '/soapbox/admin',
icon: require('@tabler/icons/icons/dashboard.svg'),
text: <FormattedMessage id='tabs_bar.dashboard' defaultMessage='Dashboard' />,
2022-04-28 14:20:21 -07:00
count: dashboardCount,
});
}
2022-04-23 13:40:54 -07:00
if (features.publicTimeline) {
menu.push(null);
}
}
2022-04-23 13:40:54 -07:00
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 : <FormattedMessage id='tabs_bar.all' defaultMessage='All' />,
});
}
2022-04-23 13:40:54 -07:00
if (features.publicTimeline && features.federating) {
menu.push({
to: '/timeline/fediverse',
icon: require('icons/fediverse.svg'),
text: <FormattedMessage id='tabs_bar.fediverse' defaultMessage='Fediverse' />,
});
}
return menu;
};
const menu = makeMenu();
2022-04-30 09:45:58 -07:00
/** Conditionally render the supported messages link */
const renderMessagesLink = (): React.ReactNode => {
if (features.chats) {
return (
<SidebarNavigationLink
to='/chats'
icon={require('@tabler/icons/icons/messages.svg')}
count={chatsCount}
text={<FormattedMessage id='tabs_bar.chats' defaultMessage='Chats' />}
/>
);
}
if (features.directTimeline || features.conversations) {
return (
<SidebarNavigationLink
to='/messages'
icon={require('@tabler/icons/icons/mail.svg')}
2022-04-30 09:45:58 -07:00
text={<FormattedMessage id='navigation.direct_messages' defaultMessage='Messages' />}
/>
);
}
return null;
};
2022-03-21 11:09:01 -07:00
return (
<div>
<div className='flex flex-col space-y-2'>
<SidebarNavigationLink
to='/'
icon={require('icons/feed.svg')}
2022-04-12 18:10:47 -07:00
text={<FormattedMessage id='tabs_bar.home' defaultMessage='Home' />}
2022-03-21 11:09:01 -07:00
/>
<SidebarNavigationLink
to='/search'
icon={require('@tabler/icons/icons/search.svg')}
text={<FormattedMessage id='tabs_bar.search' defaultMessage='Search' />}
/>
2022-03-21 11:09:01 -07:00
{account && (
<>
<SidebarNavigationLink
to={`/@${account.acct}`}
2022-03-21 11:09:01 -07:00
icon={require('icons/user.svg')}
text={<FormattedMessage id='tabs_bar.profile' defaultMessage='Profile' />}
/>
<SidebarNavigationLink
to='/notifications'
2022-05-11 13:37:15 -07:00
icon={require('@tabler/icons/icons/bell.svg')}
2022-03-21 11:09:01 -07:00
count={notificationCount}
2022-04-12 18:10:47 -07:00
text={<FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' />}
2022-03-21 11:09:01 -07:00
/>
<SidebarNavigationLink
to='/settings'
icon={require('@tabler/icons/icons/settings.svg')}
2022-03-21 11:09:01 -07:00
text={<FormattedMessage id='tabs_bar.settings' defaultMessage='Settings' />}
/>
</>
)}
2022-04-30 09:45:58 -07:00
{account && renderMessagesLink()}
2022-03-21 11:09:01 -07:00
{menu.length > 0 && (
<DropdownMenu items={menu}>
<SidebarNavigationLink
icon={require('@tabler/icons/icons/dots-circle-horizontal.svg')}
2022-04-28 14:20:21 -07:00
count={dashboardCount}
text={<FormattedMessage id='tabs_bar.more' defaultMessage='More' />}
/>
</DropdownMenu>
2022-04-12 18:10:47 -07:00
)}
2022-03-21 11:09:01 -07:00
</div>
{account && (
<ComposeButton />
)}
</div>
);
};
export default SidebarNavigation;