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

62 lines
1.9 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'
2020-02-28 15:20:47 +00:00
import { fetchAccountByUsername } from '../actions/accounts'
import { makeGetAccount } from '../selectors'
2020-02-24 21:56:07 +00:00
import LinkFooter from '../components/link_footer'
2020-02-28 15:20:47 +00:00
import ProfileStatsPanel from '../components/panel/profile_stats_panel'
2020-02-24 21:56:07 +00:00
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 account = null
2020-02-28 15:20:47 +00:00
if (!accountFetchError) {
2020-02-24 21:56:07 +00:00
account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase())
2019-07-02 08:10:25 +01:00
}
2020-02-28 15:20:47 +00:00
const getAccount = makeGetAccount()
2019-07-02 08:10:25 +01:00
return {
2020-02-28 15:20:47 +00:00
account: account ? getAccount(state, account.get('id')) : null,
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 = {
2020-02-28 15:20:47 +00:00
params: PropTypes.object.isRequired,
2019-07-02 08:10:25 +01:00
account: ImmutablePropTypes.map,
2020-02-28 15:20:47 +00:00
dispatch: PropTypes.func.isRequired,
children: PropTypes.node,
2020-02-24 21:56:07 +00:00
}
2019-07-02 08:10:25 +01:00
2020-02-28 15:20:47 +00:00
componentWillMount() {
const { dispatch, params: { username } } = this.props
dispatch(fetchAccountByUsername(username))
}
2020-01-27 19:46:42 +00:00
render() {
2020-02-28 15:20:47 +00:00
const { account } = this.props
2019-07-02 08:10:25 +01:00
return (
2020-02-24 21:56:07 +00:00
<ProfileLayout
account={account}
layout={(
<Fragment>
2020-02-28 15:20:47 +00:00
<ProfileStatsPanel account={account} />
<ProfileInfoPanel account={account} />
<MediaGalleryPanel account={account} />
2020-02-24 21:56:07 +00:00
<LinkFooter />
</Fragment>
)}
>
2020-02-28 15:20:47 +00:00
{ this.props.children }
2020-02-17 17:50:29 +00:00
</ProfileLayout>
2019-07-02 08:10:25 +01:00
)
}
}