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

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-02-24 21:56:07 +00:00
import { Fragment } from 'react'
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import LinkFooter from '../components/link_footer'
import ProfileInfoPanel from '../components/panel/profile_info_panel'
import MediaGalleryPanel from '../components/panel/media_gallery_panel'
import ProfileLayout from '../layouts/profile_layout'
2019-07-02 08:10:25 +01:00
const mapStateToProps = (state, { params: { username }, withReplies = false }) => {
2020-02-24 21:56:07 +00:00
const accounts = state.getIn(['accounts'])
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase())
2019-07-02 08:10:25 +01:00
2020-02-24 21:56:07 +00:00
let accountId = -1
let account = null
let accountUsername = username
2019-07-02 08:10:25 +01:00
if (accountFetchError) {
2020-02-24 21:56:07 +00:00
accountId = null
2019-07-02 08:10:25 +01:00
}
else {
2020-02-24 21:56:07 +00:00
account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase())
accountId = account ? account.getIn(['id'], null) : -1
accountUsername = account ? account.getIn(['acct'], '') : ''
2019-07-02 08:10:25 +01:00
}
//Children components fetch information
return {
account,
accountId,
accountUsername,
2020-02-24 21:56:07 +00:00
}
}
2019-07-02 08:10:25 +01:00
2020-02-24 21:56:07 +00:00
export default
@connect(mapStateToProps)
2019-07-02 08:10:25 +01:00
class ProfilePage extends ImmutablePureComponent {
static propTypes = {
account: ImmutablePropTypes.map,
accountUsername: PropTypes.string.isRequired,
2020-01-27 19:46:42 +00:00
accountId: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
children: PropTypes.node,
2020-02-24 21:56:07 +00:00
}
2019-07-02 08:10:25 +01:00
2020-01-27 19:46:42 +00:00
render() {
2020-02-24 21:56:07 +00:00
const { accountId, account, accountUsername } = this.props
2019-07-02 08:10:25 +01:00
return (
2020-02-24 21:56:07 +00:00
<ProfileLayout
account={account}
layout={(
<Fragment>
<ProfileInfoPanel />
<MediaGalleryPanel />
<LinkFooter />
</Fragment>
)}
>
{ /* this.props.children */ }
2020-02-17 17:50:29 +00:00
</ProfileLayout>
2019-07-02 08:10:25 +01:00
)
}
}