Progress
This commit is contained in:
@@ -3,25 +3,30 @@ import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||
import { fetchAccountByUsername } from '../actions/accounts'
|
||||
import { makeGetAccount } from '../selectors'
|
||||
import { me } from '../initial_state'
|
||||
import LinkFooter from '../components/link_footer'
|
||||
import ProfileStatsPanel from '../components/panel/profile_stats_panel'
|
||||
import ProfileInfoPanel from '../components/panel/profile_info_panel'
|
||||
import MediaGalleryPanel from '../components/panel/media_gallery_panel'
|
||||
import ColumnIndicator from '../components/column_indicator'
|
||||
import ProfileLayout from '../layouts/profile_layout'
|
||||
|
||||
const mapStateToProps = (state, { params: { username }, withReplies = false }) => {
|
||||
const mapStateToProps = (state, { params: { username } }) => {
|
||||
const accounts = state.getIn(['accounts'])
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() == username.toLowerCase())
|
||||
const account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase())
|
||||
|
||||
let account = null
|
||||
if (!accountFetchError) {
|
||||
account = accounts.find(acct => username.toLowerCase() == acct.getIn(['acct'], '').toLowerCase())
|
||||
}
|
||||
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))
|
||||
|
||||
const getAccount = makeGetAccount()
|
||||
|
||||
return {
|
||||
account: account ? getAccount(state, account.get('id')) : null,
|
||||
unavailable,
|
||||
account: accountId !== -1 ? getAccount(state, accountId) : null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +34,11 @@ export default
|
||||
@connect(mapStateToProps)
|
||||
class ProfilePage extends ImmutablePureComponent {
|
||||
static propTypes = {
|
||||
children: PropTypes.node,
|
||||
params: PropTypes.object.isRequired,
|
||||
account: ImmutablePropTypes.map,
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
children: PropTypes.node,
|
||||
unavailable: PropTypes.bool.isRequired,
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
@@ -41,7 +47,11 @@ class ProfilePage extends ImmutablePureComponent {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { account } = this.props
|
||||
const {
|
||||
account,
|
||||
children,
|
||||
unavailable
|
||||
} = this.props
|
||||
|
||||
return (
|
||||
<ProfileLayout
|
||||
@@ -55,7 +65,15 @@ class ProfilePage extends ImmutablePureComponent {
|
||||
</Fragment>
|
||||
)}
|
||||
>
|
||||
{ this.props.children }
|
||||
{
|
||||
!account && <ColumnIndicator type='loading' />
|
||||
}
|
||||
{
|
||||
!!account && !unavailable &&
|
||||
React.cloneElement(children, {
|
||||
account,
|
||||
})
|
||||
}
|
||||
</ProfileLayout>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user