import classNames from 'classnames'; import React from 'react'; import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { useDispatch } from 'react-redux'; import { Link, NavLink } from 'react-router-dom'; import { logOut, switchAccount } from 'soapbox/actions/auth'; import { fetchOwnAccounts } 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 { useAppSelector, useSoapboxConfig, useFeatures } from 'soapbox/hooks'; import { makeGetAccount, makeGetOtherAccounts } from 'soapbox/selectors'; import { getBaseURL } from 'soapbox/utils/accounts'; import { 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' }, importData: { id: 'navigation_bar.import_data', defaultMessage: 'Import data' }, 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' }, invites: { id: 'navigation_bar.invites', defaultMessage: 'Invites' }, developers: { id: 'navigation.developers', defaultMessage: 'Developers' }, addAccount: { id: 'profile_dropdown.add_account', defaultMessage: 'Add an existing account' }, }); interface ISidebarLink { to: string, icon: string, text: string | JSX.Element, onClick: React.EventHandler, } const SidebarLink: React.FC = ({ to, icon, text, onClick }) => (
{text}
); const getOtherAccounts = makeGetOtherAccounts(); const SidebarMenu: React.FC = (): JSX.Element | null => { const intl = useIntl(); const dispatch = useDispatch(); const { logo } = useSoapboxConfig(); const features = useFeatures(); const getAccount = makeGetAccount(); const instance = useAppSelector((state) => state.instance); 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 baseURL = account ? getBaseURL(account) : ''; 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 => { return (e) => { e.preventDefault(); dispatch(switchAccount(account.id)); }; }; const onClickLogOut: React.MouseEventHandler = (e) => { e.preventDefault(); dispatch(logOut(intl)); }; const handleSwitcherClick: React.MouseEventHandler = (e) => { e.preventDefault(); setSwitcher((prevState) => (!prevState)); }; const renderAccount = (account: AccountEntity) => (
); React.useEffect(() => { dispatch(fetchOwnAccounts()); }, []); if (!account) return null; return (
{logo ? ( Logo ): ( )} {switcher && (
{otherAccounts.map(account => renderAccount(account))} {intl.formatMessage(messages.addAccount)}
)}

{features.bookmarks && ( )} {features.lists && ( )} {instance.invites_enabled && ( )} {settings.get('isDeveloper') && ( )} {features.publicTimeline && <>
} onClick={onClose} /> {features.federating && ( } onClick={onClose} /> )} }
{features.federating && ( )} {features.filters && ( )} {account.admin && ( )} {features.importAPI && ( )} {features.federating && (features.accountMoving ? ( ) : features.accountAliasesAPI && ( ))}
); }; export default SidebarMenu;