/* eslint-disable jsx-a11y/interactive-supports-focus */ import clsx from 'clsx'; import React from 'react'; import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { Link, NavLink } from 'react-router-dom'; import { fetchOwnAccounts, logOut, switchAccount } from 'soapbox/actions/auth'; import { getSettings } from 'soapbox/actions/settings'; import { closeSidebar } from 'soapbox/actions/sidebar'; import Account from 'soapbox/components/account'; import { Stack } from 'soapbox/components/ui'; import ProfileStats from 'soapbox/features/ui/components/profile-stats'; import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks'; import { makeGetAccount, makeGetOtherAccounts } from 'soapbox/selectors'; import { Divider, HStack, Icon, IconButton, Text } from './ui'; import type { List as ImmutableList } from 'immutable'; import type { Account as AccountEntity } from 'soapbox/types/entities'; const messages = defineMessages({ followers: { id: 'account.followers', defaultMessage: 'Followers' }, follows: { id: 'account.follows', defaultMessage: 'Follows' }, profile: { id: 'account.profile', defaultMessage: 'Profile' }, preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, domainBlocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, filters: { id: 'navigation_bar.filters', defaultMessage: 'Muted words' }, soapboxConfig: { id: 'navigation_bar.soapbox_config', defaultMessage: 'Soapbox config' }, accountMigration: { id: 'navigation_bar.account_migration', defaultMessage: 'Move account' }, accountAliases: { id: 'navigation_bar.account_aliases', defaultMessage: 'Account aliases' }, logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' }, bookmarks: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' }, lists: { id: 'column.lists', defaultMessage: 'Lists' }, groups: { id: 'column.groups', defaultMessage: 'Groups' }, events: { id: 'column.events', defaultMessage: 'Events' }, invites: { id: 'navigation_bar.invites', defaultMessage: 'Invites' }, developers: { id: 'navigation.developers', defaultMessage: 'Developers' }, addAccount: { id: 'profile_dropdown.add_account', defaultMessage: 'Add an existing account' }, followRequests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' }, close: { id: 'lightbox.close', defaultMessage: 'Close' }, }); interface ISidebarLink { href?: string to?: string icon: string text: string | JSX.Element onClick: React.EventHandler } const SidebarLink: React.FC = ({ href, to, icon, text, onClick }) => { const body = (
{text}
); if (to) { return ( {body} ); } return ( {body} ); }; const getOtherAccounts = makeGetOtherAccounts(); const SidebarMenu: React.FC = (): JSX.Element | null => { const intl = useIntl(); const dispatch = useAppDispatch(); const features = useFeatures(); const getAccount = makeGetAccount(); const me = useAppSelector((state) => state.me); const account = useAppSelector((state) => me ? getAccount(state, me) : null); const otherAccounts: ImmutableList = useAppSelector((state) => getOtherAccounts(state)); const sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen); const settings = useAppSelector((state) => getSettings(state)); const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count()); const closeButtonRef = React.useRef(null); const [switcher, setSwitcher] = React.useState(false); const onClose = () => dispatch(closeSidebar()); const handleClose = () => { setSwitcher(false); onClose(); }; const handleSwitchAccount = (account: AccountEntity): React.MouseEventHandler => (e) => { e.preventDefault(); dispatch(switchAccount(account.id)); }; const onClickLogOut: React.MouseEventHandler = (e) => { e.preventDefault(); dispatch(logOut()); }; const handleSwitcherClick: React.MouseEventHandler = (e) => { e.preventDefault(); setSwitcher((prevState) => (!prevState)); }; const renderAccount = (account: AccountEntity) => (
); React.useEffect(() => { dispatch(fetchOwnAccounts()); }, []); if (!account) return null; return (
{(account.locked || followRequestsCount > 0) && ( )} {features.bookmarks && ( )} {features.groups && ( )} {features.lists && ( )} {features.events && ( )} {settings.get('isDeveloper') && ( )} {features.publicTimeline && <> : } onClick={onClose} /> {features.federating && ( } onClick={onClose} /> )} } {features.federating && ( )} {features.filters && ( )} {account.admin && ( )} {switcher && (
{otherAccounts.map(account => renderAccount(account))} {intl.formatMessage(messages.addAccount)}
)}
{/* Dummy element to keep Close Icon visible */}
); }; export default SidebarMenu;