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

97 lines
2.9 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { FormattedMessage } from 'react-intl';
2022-11-15 08:00:49 -08:00
import ThumbNavigationLink from 'soapbox/components/thumb-navigation-link';
import { useStatContext } from 'soapbox/contexts/stat-context';
2023-06-14 05:05:25 -07:00
import { useAppSelector, useFeatures, useGroupsPath, useOwnAccount } from 'soapbox/hooks';
const ThumbNavigation: React.FC = (): JSX.Element => {
2023-06-25 10:35:09 -07:00
const { account } = useOwnAccount();
2023-06-14 05:05:25 -07:00
const features = useFeatures();
const groupsPath = useGroupsPath();
const { unreadChatsCount } = useStatContext();
const notificationCount = useAppSelector((state) => state.notifications.unread);
2022-04-13 16:15:23 -07:00
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
2022-04-30 09:45:58 -07:00
/** Conditionally render the supported messages link */
const renderMessagesLink = (): React.ReactNode => {
if (features.chats) {
return (
<ThumbNavigationLink
2022-12-06 13:16:36 -08:00
src={require('@tabler/icons/messages.svg')}
text={<FormattedMessage id='navigation.chats' defaultMessage='Chats' />}
2022-04-30 09:45:58 -07:00
to='/chats'
exact
count={unreadChatsCount}
countMax={9}
2022-04-30 09:45:58 -07:00
/>
);
}
if (features.directTimeline || features.conversations) {
return (
<ThumbNavigationLink
src={require('@tabler/icons/mail.svg')}
2022-04-30 09:45:58 -07:00
text={<FormattedMessage id='navigation.direct_messages' defaultMessage='Messages' />}
to='/messages'
paths={['/messages', '/conversations']}
/>
);
}
return null;
};
return (
<div className='thumb-navigation'>
<ThumbNavigationLink
src={require('@tabler/icons/home.svg')}
text={<FormattedMessage id='navigation.home' defaultMessage='Home' />}
to='/'
exact
/>
2023-06-14 05:05:25 -07:00
{features.groups && (
<ThumbNavigationLink
src={require('@tabler/icons/circles.svg')}
text={<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />}
to={groupsPath}
exact
/>
)}
<ThumbNavigationLink
src={require('@tabler/icons/search.svg')}
text={<FormattedMessage id='navigation.search' defaultMessage='Search' />}
to='/search'
exact
/>
{account && (
<ThumbNavigationLink
src={require('@tabler/icons/bell.svg')}
text={<FormattedMessage id='navigation.notifications' defaultMessage='Alerts' />}
to='/notifications'
exact
count={notificationCount}
/>
)}
2022-04-30 09:45:58 -07:00
{account && renderMessagesLink()}
2022-04-13 16:15:23 -07:00
{(account && account.staff) && (
<ThumbNavigationLink
src={require('@tabler/icons/dashboard.svg')}
text={<FormattedMessage id='navigation.dashboard' defaultMessage='Dashboard' />}
2022-04-30 09:31:04 -07:00
to='/soapbox/admin'
count={dashboardCount}
/>
2022-04-13 16:15:23 -07:00
)}
</div>
);
};
export default ThumbNavigation;