gab-social/app/javascript/gabsocial/pages/profile_page.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

import { Fragment } from 'react';
2019-07-02 08:10:25 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import HeaderContainer from '../features/account_timeline/containers/header_container';
import {WhoToFollowPanel, SignUpPanel} from '../components/panel';
import LinkFooter from '../components/link_footer';
import ProfileInfoPanel from '../features/account_timeline/components/profile_info_panel/profile_info_panel';
import ColumnsArea from '../components/columns_area';
2019-07-02 08:10:25 +01:00
const mapStateToProps = (state, { params: { username }, withReplies = false }) => {
const accounts = state.getIn(['accounts']);
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase());
let accountId = -1;
let account = null;
let accountUsername = username;
if (accountFetchError) {
accountId = null;
}
else {
account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase());
accountId = account ? account.getIn(['id'], null) : -1;
accountUsername = account ? account.getIn(['acct'], '') : '';
}
//Children components fetch information
return {
account,
accountId,
accountUsername,
};
};
export default @connect(mapStateToProps)
class ProfilePage extends ImmutablePureComponent {
static propTypes = {
account: ImmutablePropTypes.map,
accountUsername: PropTypes.string.isRequired,
accountId: PropTypes.number.isRequired,
children: PropTypes.node,
2019-07-02 08:10:25 +01:00
};
render () {
const {accountId, account, accountUsername} = this.props;
2019-07-02 08:10:25 +01:00
return (
<ColumnsArea
layout={{
TOP: <HeaderContainer accountId={accountId} username={accountUsername} />,
RIGHT: (
<Fragment>
<SignUpPanel />
<WhoToFollowPanel />
<LinkFooter />
</Fragment>
),
LEFT: <ProfileInfoPanel username={accountUsername} account={account} />,
}}
>
{this.props.children}
</ColumnsArea>
2019-07-02 08:10:25 +01:00
)
}
}