bigbuffet-rw/src/pages/profile-page.tsx

133 lines
3.8 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';
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,
AccountNotePanel,
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 & 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-07-31 10:29:27 -07:00
if (ownAccount || account.pleroma?.hide_favorites === false) {
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} />
<ProfileInfoPanel username={username} account={account} />
2022-04-29 15:59:30 -07:00
{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 && (
<CtaBanner />
2022-05-10 03:17:14 -07:00
)}
2022-04-29 15:59:30 -07:00
</Layout.Main>
<Layout.Aside>
{!me && (
<SignUpPanel />
2022-04-29 15:59:30 -07:00
)}
{features.notes && account && account?.id !== me && (
<AccountNotePanel account={account} />
)}
<ProfileMediaPanel account={account} />
{(account && account.fields.length > 0) && (
<ProfileFieldsPanel account={account} />
2022-04-29 15:59:30 -07:00
)}
{(features.accountEndorsements && account && isLocal(account)) ? (
<PinnedAccountsPanel account={account} limit={5} />
) : me && features.suggestions && (
<WhoToFollowPanel limit={3} />
2022-04-29 15:59:30 -07:00
)}
<LinkFooter key='link-footer' />
</Layout.Aside>
</>
);
};
export default ProfilePage;