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

89 lines
2.7 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-03-04 22:26:01 +00:00
import { me } from '../initial_state'
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'
2020-03-04 22:26:01 +00:00
import ColumnIndicator from '../components/column_indicator'
2020-02-24 21:56:07 +00:00
import ProfileLayout from '../layouts/profile_layout'
2019-07-02 08:10:25 +01:00
2020-03-04 22:26:01 +00:00
const mapStateToProps = (state, { params: { username } }) => {
2020-02-24 21:56:07 +00:00
const accounts = state.getIn(['accounts'])
2020-03-04 22:26:01 +00:00
const account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase())
2019-07-02 08:10:25 +01:00
2020-03-04 22:26:01 +00:00
const accountId = !!account ? account.get('id') : -1
const isBlocked = state.getIn(['relationships', accountId, 'blocked_by'], false)
const isLocked = state.getIn(['accounts', accountId, 'locked'], false)
const isFollowing = state.getIn(['relationships', accountId, 'following'], false)
const unavailable = (me === accountId) ? false : (isBlocked || (isLocked && !isFollowing))
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-03-04 22:26:01 +00:00
unavailable,
account: accountId !== -1 ? getAccount(state, accountId) : 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-03-04 22:26:01 +00:00
children: PropTypes.node,
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,
2020-03-04 22:26:01 +00:00
unavailable: PropTypes.bool.isRequired,
2020-02-24 21:56:07 +00:00
}
2019-07-02 08:10:25 +01:00
2020-03-12 16:09:15 +00:00
componentDidMount() {
const { account, params: { username } } = this.props
if (!!account) {
document.title = `${account.get('display_name')} (@${username}) - Gab`
} else {
document.title = `@${username} - Gab`
}
}
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-03-04 22:26:01 +00:00
const {
account,
children,
unavailable
} = 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-03-04 22:26:01 +00:00
{
!account && <ColumnIndicator type='loading' />
}
{
!!account && !unavailable &&
React.cloneElement(children, {
account,
})
}
2020-02-17 17:50:29 +00:00
</ProfileLayout>
2019-07-02 08:10:25 +01:00
)
}
}