import React from 'react'; import { Helmet } from 'react-helmet-async'; import { FormattedMessage } from 'react-intl'; import { Redirect, useHistory } from 'react-router-dom'; import { useAccountLookup } from 'pl-fe/api/hooks/accounts/useAccountLookup'; import Column from 'pl-fe/components/ui/column'; import Layout from 'pl-fe/components/ui/layout'; import Tabs from 'pl-fe/components/ui/tabs'; import Header from 'pl-fe/features/account/components/header'; import LinkFooter from 'pl-fe/features/ui/components/link-footer'; import { WhoToFollowPanel, ProfileInfoPanel, ProfileMediaPanel, ProfileFieldsPanel, SignUpPanel, PinnedAccountsPanel, AccountNotePanel, } from 'pl-fe/features/ui/util/async-components'; import { useAppSelector, useFeatures, usePlFeConfig } from 'pl-fe/hooks'; import { getAcct } from 'pl-fe/utils/accounts'; interface IProfileLayout { params?: { username?: string; }; children: React.ReactNode; } /** Layout to display a user's profile. */ const ProfileLayout: React.FC = ({ params, children }) => { const history = useHistory(); const username = params?.username || ''; const { account } = useAccountLookup(username, { withRelationship: true, withScrobble: true }); const me = useAppSelector(state => state.me); const features = useFeatures(); const { displayFqn } = usePlFeConfig(); // Fix case of username if (account && account.acct !== username) { return ; } const tabItems = [ { text: , to: `/@${username}`, name: 'profile', }, { text: , to: `/@${username}/with_replies`, name: 'replies', }, { text: , to: `/@${username}/media`, name: 'media', }, ]; if (account) { const ownAccount = account.id === me; if (ownAccount || account.hide_favorites === false) { tabItems.push({ text: , to: `/@${account.acct}/favorites`, name: 'likes', }); } } let activeItem; const pathname = history.location.pathname.replace(`@${username}/`, ''); if (pathname.endsWith('/with_replies')) { activeItem = 'replies'; } else if (pathname.endsWith('/media')) { activeItem = 'media'; } else if (pathname.endsWith('/favorites')) { activeItem = 'likes'; } else { activeItem = 'profile'; } const showTabs = !['/following', '/followers', '/pins'].some(path => pathname.endsWith(path)); return ( <> {account?.local === false && ( )}
{account && showTabs && ( )} {children}
{!me && ( )} {features.notes && account && account?.id !== me && ( )} {(account && account.fields.length > 0) && ( )} {(features.accountEndorsements && account && account.local) ? ( ) : me && features.suggestions && ( )} ); }; export { ProfileLayout as default };