bigbuffet-rw/app/soapbox/pages/profile-page.tsx

144 lines
4.5 KiB
TypeScript
Raw Normal View History

2022-04-29 15:59:30 -07:00
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { Redirect, useHistory } from 'react-router-dom';
import { useAccountLookup } from 'soapbox/api/hooks';
2022-08-11 11:24:46 -07:00
import { Column, Layout, Tabs } from 'soapbox/components/ui';
import Header from 'soapbox/features/account/components/header';
2022-11-16 05:32:32 -08:00
import LinkFooter from 'soapbox/features/ui/components/link-footer';
import BundleContainer from 'soapbox/features/ui/containers/bundle-container';
2022-04-29 15:59:30 -07:00
import {
WhoToFollowPanel,
ProfileInfoPanel,
ProfileMediaPanel,
2022-04-29 19:05:39 -07:00
ProfileFieldsPanel,
2022-04-29 15:59:30 -07:00
SignUpPanel,
2022-05-10 03:17:14 -07:00
CtaBanner,
PinnedAccountsPanel,
2022-04-29 15:59:30 -07:00
} from 'soapbox/features/ui/util/async-components';
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
import { getAcct, isLocal } from 'soapbox/utils/accounts';
2022-04-29 15:59:30 -07:00
interface IProfilePage {
params?: {
username?: string
}
children: React.ReactNode
2022-04-29 15:59:30 -07:00
}
/** Page to display a user's profile. */
2022-04-29 15:59:30 -07:00
const ProfilePage: React.FC<IProfilePage> = ({ params, children }) => {
const history = useHistory();
const username = params?.username || '';
2022-04-29 15:59:30 -07:00
2023-06-25 10:04:30 -07:00
const { account } = useAccountLookup(username, { withRelationship: true });
2022-04-29 15:59:30 -07:00
const me = useAppSelector(state => state.me);
const features = useFeatures();
const { displayFqn } = useSoapboxConfig();
// Fix case of username
if (account && account.acct !== username) {
return <Redirect to={`/@${account.acct}`} />;
}
2022-04-29 15:59:30 -07:00
const tabItems = [
{
text: <FormattedMessage id='account.posts' defaultMessage='Posts' />,
to: `/@${username}`,
2022-04-29 15:59:30 -07:00
name: 'profile',
},
{
text: <FormattedMessage id='account.posts_with_replies' defaultMessage='Posts and replies' />,
to: `/@${username}/with_replies`,
2022-04-29 15:59:30 -07:00
name: 'replies',
},
{
text: <FormattedMessage id='account.media' defaultMessage='Media' />,
to: `/@${username}/media`,
2022-04-29 15:59:30 -07:00
name: 'media',
},
];
if (account) {
const ownAccount = account.id === me;
2023-06-20 12:24:39 -07:00
if (ownAccount || account.pleroma?.hide_favorites !== true) {
2022-04-29 15:59:30 -07:00
tabItems.push({
text: <FormattedMessage id='navigation_bar.favourites' defaultMessage='Likes' />,
to: `/@${account.acct}/favorites`,
name: 'likes',
});
}
}
let activeItem;
const pathname = history.location.pathname.replace(`@${username}/`, '');
if (pathname.endsWith('/with_replies')) {
2022-04-29 15:59:30 -07:00
activeItem = 'replies';
} else if (pathname.endsWith('/media')) {
2022-04-29 15:59:30 -07:00
activeItem = 'media';
} else if (pathname.endsWith('/favorites')) {
2022-04-29 15:59:30 -07:00
activeItem = 'likes';
} else {
2022-04-29 15:59:30 -07:00
activeItem = 'profile';
}
const showTabs = !['/following', '/followers', '/pins'].some(path => pathname.endsWith(path));
2022-04-29 15:59:30 -07:00
return (
<>
<Layout.Main>
2023-04-11 05:55:17 -07:00
<Column size='lg' label={account ? `@${getAcct(account, displayFqn)}` : ''} withHeader={false}>
2022-04-29 15:59:30 -07:00
<div className='space-y-4'>
2022-08-11 12:02:01 -07:00
<Header account={account} />
2022-04-29 15:59:30 -07:00
<BundleContainer fetchComponent={ProfileInfoPanel}>
{Component => <Component username={username} account={account} />}
2022-04-29 15:59:30 -07:00
</BundleContainer>
{account && showTabs && (
<Tabs key={`profile-tabs-${account.id}`} items={tabItems} activeItem={activeItem} />
2022-04-29 15:59:30 -07:00
)}
{children}
</div>
</Column>
2022-05-10 03:17:14 -07:00
{!me && (
<BundleContainer fetchComponent={CtaBanner}>
{Component => <Component key='cta-banner' />}
</BundleContainer>
)}
2022-04-29 15:59:30 -07:00
</Layout.Main>
<Layout.Aside>
{!me && (
<BundleContainer fetchComponent={SignUpPanel}>
{Component => <Component key='sign-up-panel' />}
</BundleContainer>
)}
<BundleContainer fetchComponent={ProfileMediaPanel}>
{Component => <Component account={account} />}
</BundleContainer>
{account && account.fields.length && (
2022-04-29 19:05:39 -07:00
<BundleContainer fetchComponent={ProfileFieldsPanel}>
{Component => <Component account={account} />}
2022-04-29 15:59:30 -07:00
</BundleContainer>
)}
{(features.accountEndorsements && account && isLocal(account)) ? (
<BundleContainer fetchComponent={PinnedAccountsPanel}>
{Component => <Component account={account} limit={5} key='pinned-accounts-panel' />}
</BundleContainer>
) : me && features.suggestions && (
2022-04-29 15:59:30 -07:00
<BundleContainer fetchComponent={WhoToFollowPanel}>
2022-09-26 12:22:00 -07:00
{Component => <Component limit={3} key='wtf-panel' />}
2022-04-29 15:59:30 -07:00
</BundleContainer>
)}
<LinkFooter key='link-footer' />
</Layout.Aside>
</>
);
};
export default ProfilePage;