2022-04-29 15:59:30 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { Redirect, useHistory } from 'react-router-dom';
|
|
|
|
|
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,
|
2022-07-21 12:37:14 -07:00
|
|
|
PinnedAccountsPanel,
|
2022-04-29 15:59:30 -07:00
|
|
|
} from 'soapbox/features/ui/util/async-components';
|
|
|
|
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
|
2022-08-11 11:57:33 -07:00
|
|
|
import { findAccountByUsername, makeGetAccount } from 'soapbox/selectors';
|
2022-07-21 12:37:14 -07:00
|
|
|
import { getAcct, isLocal } from 'soapbox/utils/accounts';
|
2022-04-29 15:59:30 -07:00
|
|
|
|
|
|
|
interface IProfilePage {
|
|
|
|
params?: {
|
2023-02-15 13:26:27 -08:00
|
|
|
username?: string
|
|
|
|
}
|
|
|
|
children: React.ReactNode
|
2022-04-29 15:59:30 -07:00
|
|
|
}
|
|
|
|
|
2022-08-11 11:57:33 -07:00
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
2022-05-04 11:08:49 -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();
|
2022-05-04 11:08:49 -07:00
|
|
|
const username = params?.username || '';
|
2022-04-29 15:59:30 -07:00
|
|
|
|
2022-08-11 11:57:33 -07:00
|
|
|
const account = useAppSelector(state => {
|
|
|
|
if (username) {
|
|
|
|
const account = findAccountByUsername(state, username);
|
|
|
|
if (account) {
|
|
|
|
return getAccount(state, account.id) || undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-04-29 15:59:30 -07:00
|
|
|
|
|
|
|
const me = useAppSelector(state => state.me);
|
|
|
|
const features = useFeatures();
|
|
|
|
const { displayFqn } = useSoapboxConfig();
|
|
|
|
|
2022-05-04 11:08:49 -07:00
|
|
|
// 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' />,
|
2022-05-04 11:08:49 -07:00
|
|
|
to: `/@${username}`,
|
2022-04-29 15:59:30 -07:00
|
|
|
name: 'profile',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: <FormattedMessage id='account.posts_with_replies' defaultMessage='Posts and replies' />,
|
2022-05-04 11:08:49 -07:00
|
|
|
to: `/@${username}/with_replies`,
|
2022-04-29 15:59:30 -07:00
|
|
|
name: 'replies',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: <FormattedMessage id='account.media' defaultMessage='Media' />,
|
2022-05-04 11:08:49 -07:00
|
|
|
to: `/@${username}/media`,
|
2022-04-29 15:59:30 -07:00
|
|
|
name: 'media',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (account) {
|
|
|
|
const ownAccount = account.id === me;
|
|
|
|
if (ownAccount || !account.pleroma.get('hide_favorites', true)) {
|
|
|
|
tabItems.push({
|
|
|
|
text: <FormattedMessage id='navigation_bar.favourites' defaultMessage='Likes' />,
|
|
|
|
to: `/@${account.acct}/favorites`,
|
|
|
|
name: 'likes',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let activeItem;
|
2022-05-04 11:08:49 -07:00
|
|
|
const pathname = history.location.pathname.replace(`@${username}/`, '');
|
2022-08-11 11:59:06 -07:00
|
|
|
if (pathname.endsWith('/with_replies')) {
|
2022-04-29 15:59:30 -07:00
|
|
|
activeItem = 'replies';
|
2022-08-11 11:59:06 -07:00
|
|
|
} else if (pathname.endsWith('/media')) {
|
2022-04-29 15:59:30 -07:00
|
|
|
activeItem = 'media';
|
2022-08-11 11:59:06 -07:00
|
|
|
} else if (pathname.endsWith('/favorites')) {
|
2022-04-29 15:59:30 -07:00
|
|
|
activeItem = 'likes';
|
2022-05-04 11:08:49 -07:00
|
|
|
} else {
|
2022-04-29 15:59:30 -07:00
|
|
|
activeItem = 'profile';
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:57:33 -07:00
|
|
|
const showTabs = !['/following', '/followers', '/pins'].some(path => pathname.endsWith(path));
|
2022-07-13 11:54:43 -07:00
|
|
|
|
2022-04-29 15:59:30 -07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Layout.Main>
|
|
|
|
<Column label={account ? `@${getAcct(account, displayFqn)}` : ''} withHeader={false}>
|
|
|
|
<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}>
|
2022-05-04 11:08:49 -07:00
|
|
|
{Component => <Component username={username} account={account} />}
|
2022-04-29 15:59:30 -07:00
|
|
|
</BundleContainer>
|
|
|
|
|
2022-07-13 11:54:43 -07:00
|
|
|
{account && showTabs && (
|
2022-09-03 14:19:30 -07:00
|
|
|
<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>
|
2022-04-29 19:05:39 -07:00
|
|
|
{account && !account.fields.isEmpty() && (
|
|
|
|
<BundleContainer fetchComponent={ProfileFieldsPanel}>
|
|
|
|
{Component => <Component account={account} />}
|
2022-04-29 15:59:30 -07:00
|
|
|
</BundleContainer>
|
|
|
|
)}
|
2022-07-21 12:37:14 -07:00
|
|
|
{(features.accountEndorsements && account && isLocal(account)) ? (
|
|
|
|
<BundleContainer fetchComponent={PinnedAccountsPanel}>
|
|
|
|
{Component => <Component account={account} limit={5} key='pinned-accounts-panel' />}
|
|
|
|
</BundleContainer>
|
2022-10-09 15:32:09 -07:00
|
|
|
) : 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;
|