bigbuffet-rw/app/soapbox/pages/profile_page.js

175 lines
5.5 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types';
2020-03-27 13:59:38 -07:00
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
2022-03-21 11:09:01 -07:00
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
2022-03-21 11:09:01 -07:00
import { Redirect, withRouter } from 'react-router-dom';
2022-03-21 11:09:01 -07:00
import SidebarNavigation from 'soapbox/components/sidebar-navigation';
import LinkFooter from 'soapbox/features/ui/components/link_footer';
2021-09-18 14:54:47 -07:00
import BundleContainer from 'soapbox/features/ui/containers/bundle_container';
2021-09-18 15:48:13 -07:00
import {
WhoToFollowPanel,
2022-03-21 11:09:01 -07:00
TrendsPanel,
2021-09-18 17:17:55 -07:00
ProfileInfoPanel,
2022-03-21 11:09:01 -07:00
SignUpPanel,
2021-09-18 15:48:13 -07:00
} from 'soapbox/features/ui/util/async-components';
2022-03-21 11:09:01 -07:00
import { findAccountByUsername } from 'soapbox/selectors';
import { getAcct } from 'soapbox/utils/accounts';
2020-05-28 15:52:07 -07:00
import { getFeatures } from 'soapbox/utils/features';
import { displayFqn } from 'soapbox/utils/state';
2022-03-21 11:09:01 -07:00
import { Column, Layout, Tabs } from '../components/ui';
2022-01-10 14:01:24 -08:00
import HeaderContainer from '../features/account_timeline/containers/header_container';
2022-03-21 11:09:01 -07:00
import { makeGetAccount } from '../selectors';
2020-03-27 13:59:38 -07:00
const mapStateToProps = (state, { params, withReplies = false }) => {
const username = params.username || '';
2020-03-27 13:59:38 -07:00
const accounts = state.getIn(['accounts']);
2021-11-15 19:31:17 -08:00
const accountFetchError = ((state.getIn(['accounts', -1, 'username']) || '').toLowerCase() === username.toLowerCase());
2020-07-04 19:25:43 -07:00
const getAccount = makeGetAccount();
2022-03-21 11:09:01 -07:00
const me = state.get('me');
2020-03-27 13:59:38 -07:00
let accountId = -1;
let account = null;
let accountUsername = username;
if (accountFetchError) {
accountId = null;
2020-04-14 11:44:40 -07:00
} else {
account = findAccountByUsername(state, username);
2020-03-27 13:59:38 -07:00
accountId = account ? account.getIn(['id'], null) : -1;
accountUsername = account ? account.getIn(['acct'], '') : '';
}
//Children components fetch information
let realAccount;
if (!account) {
const maybeAccount = accounts.get(username);
if (maybeAccount) {
realAccount = maybeAccount;
}
}
2020-03-27 13:59:38 -07:00
return {
2022-03-21 11:09:01 -07:00
me,
2020-07-04 19:25:43 -07:00
account: accountId ? getAccount(state, accountId) : account,
2020-03-27 13:59:38 -07:00
accountId,
accountUsername,
features: getFeatures(state.get('instance')),
realAccount,
displayFqn: displayFqn(state),
2020-03-27 13:59:38 -07:00
};
};
export default @connect(mapStateToProps)
2022-03-21 11:09:01 -07:00
@withRouter
2020-03-27 13:59:38 -07:00
class ProfilePage extends ImmutablePureComponent {
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
static propTypes = {
2022-03-23 10:14:42 -07:00
account: ImmutablePropTypes.record,
2020-03-27 13:59:38 -07:00
accountUsername: PropTypes.string.isRequired,
displayFqn: PropTypes.bool,
2020-05-26 21:56:54 -07:00
features: PropTypes.object,
2020-03-27 13:59:38 -07:00
};
render() {
2022-03-21 11:09:01 -07:00
const { children, accountId, account, displayFqn, accountUsername, me, features, realAccount } = this.props;
2020-03-27 13:59:38 -07:00
if (realAccount) {
return <Redirect to={`/@${realAccount.get('acct')}`} />;
}
2022-03-21 11:09:01 -07:00
const tabItems = [
{
text: <FormattedMessage id='account.posts' defaultMessage='Posts' />,
to: `/@${accountUsername}`,
name: 'profile',
},
{
text: <FormattedMessage id='account.posts_with_replies' defaultMessage='Posts and replies' />,
to: `/@${accountUsername}/with_replies`,
name: 'replies',
},
{
text: <FormattedMessage id='account.media' defaultMessage='Media' />,
to: `/@${accountUsername}/media`,
name: 'media',
},
];
if (account) {
const ownAccount = account.get('id') === me;
if (ownAccount || !account.getIn(['pleroma', 'hide_favorites'], true)) {
tabItems.push({
text: <FormattedMessage id='navigation_bar.favourites' defaultMessage='Likes' />,
to: `/@${account.get('acct')}/favorites`,
name: 'likes',
});
}
}
const showTrendsPanel = features.trends;
const showWhoToFollowPanel = features.suggestions;
let activeItem;
const pathname = this.props.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';
}
2020-03-27 13:59:38 -07:00
return (
2022-03-21 11:09:01 -07:00
<Layout>
<Layout.Sidebar>
<SidebarNavigation />
</Layout.Sidebar>
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
<Layout.Main>
<Column label={account ? `@${getAcct(account, displayFqn)}` : null} withHeader={false}>
<div className='space-y-4'>
<HeaderContainer accountId={accountId} username={accountUsername} />
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
<BundleContainer fetchComponent={ProfileInfoPanel}>
{Component => <Component username={accountUsername} account={account} />}
</BundleContainer>
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
{account && (
<Tabs items={tabItems} activeItem={activeItem} />
)}
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
{children}
</div>
</Column>
</Layout.Main>
<Layout.Aside>
{!me && (
<BundleContainer fetchComponent={SignUpPanel}>
{Component => <Component key='sign-up-panel' />}
</BundleContainer>
)}
{showTrendsPanel && (
<BundleContainer fetchComponent={TrendsPanel}>
{Component => <Component limit={3} key='trends-panel' />}
</BundleContainer>
)}
{showWhoToFollowPanel && (
<BundleContainer fetchComponent={WhoToFollowPanel}>
{Component => <Component limit={5} key='wtf-panel' />}
</BundleContainer>
)}
<LinkFooter key='link-footer' />
</Layout.Aside>
</Layout>
2020-04-14 11:44:40 -07:00
);
2020-03-27 13:59:38 -07:00
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}