90 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-05-09 23:26:58 -04:00
import { FormattedMessage } from 'react-intl'
2020-02-24 16:56:07 -05:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-02-28 10:20:47 -05:00
import { fetchAccountByUsername } from '../actions/accounts'
import { makeGetAccount } from '../selectors'
2020-03-04 17:26:01 -05:00
import { me } from '../initial_state'
2020-04-11 18:29:19 -04:00
import PageTitle from '../features/ui/util/page_title'
2020-03-04 17:26:01 -05:00
import ColumnIndicator from '../components/column_indicator'
2020-05-09 23:26:58 -04:00
import Block from '../components/block'
2020-02-24 16:56:07 -05:00
import ProfileLayout from '../layouts/profile_layout'
2019-07-02 03:10:25 -04:00
2020-03-04 17:26:01 -05:00
const mapStateToProps = (state, { params: { username } }) => {
2020-02-24 16:56:07 -05:00
const accounts = state.getIn(['accounts'])
2020-04-07 21:06:59 -04:00
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase())
2019-07-02 03:10:25 -04:00
2020-03-04 17:26:01 -05: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 03:10:25 -04:00
2020-02-28 10:20:47 -05:00
const getAccount = makeGetAccount()
2019-07-02 03:10:25 -04:00
return {
2020-03-04 17:26:01 -05:00
unavailable,
account: accountId !== -1 ? getAccount(state, accountId) : null,
2020-02-24 16:56:07 -05:00
}
}
2019-07-02 03:10:25 -04:00
2020-04-11 18:29:19 -04:00
const mapDispatchToProps = (dispatch) => ({
onFetchAccountByUsername(username) {
dispatch(fetchAccountByUsername(username))
},
})
2020-02-24 16:56:07 -05:00
export default
2020-04-11 18:29:19 -04:00
@connect(mapStateToProps, mapDispatchToProps)
2019-07-02 03:10:25 -04:00
class ProfilePage extends ImmutablePureComponent {
2020-04-07 21:06:59 -04:00
2019-07-02 03:10:25 -04:00
static propTypes = {
2020-03-04 17:26:01 -05:00
children: PropTypes.node,
2020-02-28 10:20:47 -05:00
params: PropTypes.object.isRequired,
2019-07-02 03:10:25 -04:00
account: ImmutablePropTypes.map,
2020-04-11 18:29:19 -04:00
onFetchAccountByUsername: PropTypes.func.isRequired,
2020-03-04 17:26:01 -05:00
unavailable: PropTypes.bool.isRequired,
noSidebar: PropTypes.bool,
2020-02-24 16:56:07 -05:00
}
2019-07-02 03:10:25 -04:00
2020-03-12 12:09:15 -04:00
componentDidMount() {
2020-04-11 18:29:19 -04:00
this.props.onFetchAccountByUsername(this.props.params.username)
2020-02-28 10:20:47 -05:00
}
2020-01-27 14:46:42 -05:00
render() {
2020-03-04 17:26:01 -05:00
const {
account,
children,
2020-04-07 21:06:59 -04:00
unavailable,
noSidebar,
2020-04-11 18:29:19 -04:00
params: { username },
2020-03-04 17:26:01 -05:00
} = this.props
2019-07-02 03:10:25 -04:00
const nameHTML = !!account ? account.get('display_name_html') : ''
const name = !!account ? account.get('display_name_plain') : ''
2019-07-02 03:10:25 -04:00
return (
2020-02-24 16:56:07 -05:00
<ProfileLayout
account={account}
titleHTML={nameHTML}
2020-05-09 23:26:58 -04:00
unavailable={unavailable}
noSidebar={noSidebar}
2020-02-24 16:56:07 -05:00
>
2020-04-17 01:35:46 -04:00
<PageTitle path={`${name} (@${username})`} />
2020-03-04 17:26:01 -05:00
{
!unavailable &&
2020-03-04 17:26:01 -05:00
React.cloneElement(children, {
account,
})
}
2020-05-09 23:26:58 -04:00
{
unavailable &&
<ColumnIndicator type='error' message={
<FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />
} />
}
2020-02-17 12:50:29 -05:00
</ProfileLayout>
2019-07-02 03:10:25 -04:00
)
}
2020-04-07 21:06:59 -04:00
}