import React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { Icon, Stack } from 'soapbox/components/ui';
import { useStatContext } from 'soapbox/contexts/stat-context';
import Search from 'soapbox/features/compose/components/search';
import ComposeButton from 'soapbox/features/ui/components/compose-button';
import ProfileDropdown from 'soapbox/features/ui/components/profile-dropdown';
import { useAppSelector, useFeatures, useOwnAccount, useSettings, useInstance } from 'soapbox/hooks';
import Account from './account';
import DropdownMenu, { Menu } from './dropdown-menu';
import SidebarNavigationLink from './sidebar-navigation-link';
const messages = defineMessages({
followRequests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
bookmarks: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' },
lists: { id: 'column.lists', defaultMessage: 'Lists' },
events: { id: 'column.events', defaultMessage: 'Events' },
profileDirectory: { id: 'navigation_bar.profile_directory', defaultMessage: 'Profile directory' },
followedTags: { id: 'navigation_bar.followed_tags', defaultMessage: 'Followed hashtags' },
developers: { id: 'navigation.developers', defaultMessage: 'Developers' },
drafts: { id: 'navigation.drafts', defaultMessage: 'Drafts' },
});
/** Desktop sidebar with links to different views in the app. */
const SidebarNavigation = () => {
const intl = useIntl();
const { unreadChatsCount } = useStatContext();
const instance = useInstance();
const features = useFeatures();
const { isDeveloper } = useSettings();
const { account } = useOwnAccount();
const notificationCount = useAppSelector((state) => state.notifications.unread);
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
const draftCount = useAppSelector((state) => state.draft_statuses.size);
const restrictUnauth = instance.pleroma.metadata.restrict_unauthenticated;
const makeMenu = (): Menu => {
const menu: Menu = [];
if (account) {
if (account.locked || followRequestsCount > 0) {
menu.push({
to: '/follow_requests',
text: intl.formatMessage(messages.followRequests),
icon: require('@tabler/icons/outline/user-plus.svg'),
count: followRequestsCount,
});
}
if (features.bookmarks) {
menu.push({
to: '/bookmarks',
text: intl.formatMessage(messages.bookmarks),
icon: require('@tabler/icons/outline/bookmark.svg'),
});
}
if (features.lists) {
menu.push({
to: '/lists',
text: intl.formatMessage(messages.lists),
icon: require('@tabler/icons/outline/list.svg'),
});
}
if (features.events) {
menu.push({
to: '/events',
text: intl.formatMessage(messages.events),
icon: require('@tabler/icons/outline/calendar-event.svg'),
});
}
if (features.profileDirectory) {
menu.push({
to: '/directory',
text: intl.formatMessage(messages.profileDirectory),
icon: require('@tabler/icons/outline/address-book.svg'),
});
}
if (features.followedHashtagsList) {
menu.push({
to: '/followed_tags',
text: intl.formatMessage(messages.followedTags),
icon: require('@tabler/icons/outline/hash.svg'),
});
}
if (isDeveloper) {
menu.push({
to: '/developers',
icon: require('@tabler/icons/outline/code.svg'),
text: intl.formatMessage(messages.developers),
});
}
if (draftCount > 0) {
menu.push({
to: '/draft_statuses',
icon: require('@tabler/icons/outline/notes.svg'),
text: intl.formatMessage(messages.drafts),
count: draftCount,
});
}
}
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 && (
)}
}
/>
}
/>
{account && (
<>
}
/>
{renderMessagesLink()}
{features.groups && (
}
/>
)}
}
/>
}
/>
{account.staff && (
}
/>
)}
>
)}
{(features.publicTimeline) && (
<>
{(account || !restrictUnauth.timelines.local) && (
: }
/>
)}
{(features.federating && (account || !restrictUnauth.timelines.federated)) && (
}
/>
)}
{(features.bubbleTimeline && (account || !restrictUnauth.timelines.bubble)) && (
}
/>
)}
>
)}
{menu.length > 0 && (
}
/>
)}
{!account && (
}
/>
}
/>
)}
{account && (
)}
);
};
export { SidebarNavigation as default };