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

116 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-05-28 15:52:07 -07:00
import Helmet from 'soapbox/components/helmet';
2020-03-27 13:59:38 -07:00
import HeaderContainer from '../features/account_timeline/containers/header_container';
import WhoToFollowPanel from '../features/ui/components/who_to_follow_panel';
import LinkFooter from '../features/ui/components/link_footer';
import SignUpPanel from '../features/ui/components/sign_up_panel';
import ProfileInfoPanel from '../features/ui/components/profile_info_panel';
2020-08-14 11:01:12 -07:00
import ProfileMediaPanel from '../features/ui/components/profile_media_panel';
import { getAcct } from 'soapbox/utils/accounts';
import { displayFqn } from 'soapbox/utils/state';
2020-05-28 15:52:07 -07:00
import { getFeatures } from 'soapbox/utils/features';
2020-07-04 19:25:43 -07:00
import { makeGetAccount } from '../selectors';
import { Redirect } from 'react-router-dom';
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']);
2020-04-14 13:45:38 -07:00
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
2020-07-04 19:25:43 -07:00
const getAccount = makeGetAccount();
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 {
2020-04-14 13:45:38 -07:00
account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
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 {
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)
class ProfilePage extends ImmutablePureComponent {
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
static propTypes = {
account: ImmutablePropTypes.map,
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() {
const { children, accountId, account, displayFqn, accountUsername, features, realAccount } = this.props;
2020-05-26 21:56:54 -07:00
const bg = account ? account.getIn(['customizations', 'background']) : undefined;
2020-03-27 13:59:38 -07:00
if (realAccount) {
return <Redirect to={`/@${realAccount.get('acct')}`} />;
}
2020-03-27 13:59:38 -07:00
return (
<div className={bg && `page page--customization page--${bg}` || 'page'}>
2020-05-26 21:56:54 -07:00
{account && <Helmet>
<title>@{getAcct(account, displayFqn)}</title>
2020-05-26 21:56:54 -07:00
</Helmet>}
2020-04-14 21:21:36 -07:00
2020-03-27 13:59:38 -07:00
<div className='page__top'>
2020-04-14 11:44:40 -07:00
<HeaderContainer accountId={accountId} username={accountUsername} />
2020-03-27 13:59:38 -07:00
</div>
<div className='page__columns'>
<div className='columns-area__panels'>
<div className='columns-area__panels__pane columns-area__panels__pane--left'>
<div className='columns-area__panels__pane__inner'>
<ProfileInfoPanel username={accountUsername} account={account} />
</div>
</div>
<div className='columns-area__panels__main'>
<div className='columns-area columns-area--mobile'>
{children}
</div>
</div>
<div className='columns-area__panels__pane columns-area__panels__pane--right'>
<div className='columns-area__panels__pane__inner'>
<SignUpPanel />
{features.suggestions && <WhoToFollowPanel />}
2020-08-14 11:01:12 -07:00
{account && <ProfileMediaPanel account={account} />}
2020-03-27 13:59:38 -07:00
<LinkFooter />
</div>
</div>
</div>
</div>
</div>
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
}