import React from 'react'; import { FormattedMessage } from 'react-intl'; import { Redirect, useHistory } from 'react-router-dom'; import LinkFooter from 'soapbox/features/ui/components/link_footer'; import BundleContainer from 'soapbox/features/ui/containers/bundle_container'; import { WhoToFollowPanel, TrendsPanel, ProfileInfoPanel, ProfileMediaPanel, SignUpPanel, } from 'soapbox/features/ui/util/async-components'; import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks'; import { findAccountByUsername } from 'soapbox/selectors'; import { getAcct } from 'soapbox/utils/accounts'; import { Column, Layout, Tabs } from '../components/ui'; import HeaderContainer from '../features/account_timeline/containers/header_container'; import { makeGetAccount } from '../selectors'; const getAccount = makeGetAccount(); interface IProfilePage { params?: { username?: string, }, } const ProfilePage: React.FC = ({ params, children }) => { const history = useHistory(); const { accountId, account, accountUsername, realAccount } = useAppSelector(state => { const username = params?.username || ''; const { accounts } = state; const accountFetchError = (((state.accounts.getIn([-1, 'username']) || '') as string).toLowerCase() === username.toLowerCase()); let accountId: string | -1 | null = -1; let account = null; let accountUsername = username; if (accountFetchError) { accountId = null; } else { account = findAccountByUsername(state, username); accountId = account ? account.id : -1; accountUsername = account ? account.acct : ''; } let realAccount; if (!account) { const maybeAccount = accounts.get(username); if (maybeAccount) { realAccount = maybeAccount; } } return { account: typeof accountId === 'string' ? getAccount(state, accountId) : account, accountId, accountUsername, realAccount, }; }); const me = useAppSelector(state => state.me); const features = useFeatures(); const { displayFqn } = useSoapboxConfig(); if (realAccount) { return ; } const tabItems = [ { text: , to: `/@${accountUsername}`, name: 'profile', }, { text: , to: `/@${accountUsername}/with_replies`, name: 'replies', }, { text: , to: `/@${accountUsername}/media`, name: 'media', }, ]; if (account) { const ownAccount = account.id === me; if (ownAccount || !account.pleroma.get('hide_favorites', true)) { tabItems.push({ text: , to: `/@${account.acct}/favorites`, name: 'likes', }); } } let activeItem; const pathname = history.location.pathname.replace(`@${accountUsername}/`, ''); if (pathname.includes('with_replies')) { activeItem = 'replies'; } else if (pathname.includes('media')) { activeItem = 'media'; } else if (pathname.includes('favorites')) { activeItem = 'likes'; } else if (pathname === `/@${accountUsername}`) { activeItem = 'profile'; } return ( <>
{/* @ts-ignore */} {Component => } {account && activeItem && ( )} {children}
{!me && ( {Component => } )} {Component => } {features.trends && ( {Component => } )} {features.suggestions && ( {Component => } )} ); }; export default ProfilePage;