2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-11 23:56:18 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-04-23 07:13:29 +01:00
|
|
|
import { NavLink } from 'react-router-dom'
|
2020-06-13 00:37:14 +01:00
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
import { makeGetAccount } from '../../selectors'
|
2021-01-09 08:25:54 +00:00
|
|
|
import { fetchRelationships } from '../../actions/accounts'
|
2020-06-13 00:37:14 +01:00
|
|
|
import { shortNumberFormat } from '../../utils/numbers'
|
|
|
|
import { me } from '../../initial_state'
|
2020-02-28 15:20:47 +00:00
|
|
|
import PopoverLayout from './popover_layout'
|
2020-04-23 07:13:29 +01:00
|
|
|
import AccountActionButton from '../account_action_button'
|
2020-03-11 23:56:18 +00:00
|
|
|
import Avatar from '../avatar'
|
|
|
|
import DisplayName from '../display_name'
|
2020-12-17 06:34:00 +00:00
|
|
|
import UserStat from '../user_stat'
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-06-13 00:37:14 +01:00
|
|
|
class UserInfoPopover extends ImmutablePureComponent {
|
2020-05-13 01:36:54 +01:00
|
|
|
|
2021-01-09 08:25:54 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.checkRelationships(this.props.account)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { account } = this.props
|
|
|
|
if (prevProps.account !== account) {
|
|
|
|
this.checkRelationships(account)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkRelationships = (account) => {
|
|
|
|
if (!account) return
|
|
|
|
if (!account.get('relationship')) {
|
|
|
|
this.props.onFetchRelationships(account.get('id'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
render() {
|
2020-05-13 01:36:54 +01:00
|
|
|
const { account, isXS } = this.props
|
2020-03-11 23:56:18 +00:00
|
|
|
|
2020-06-13 00:37:14 +01:00
|
|
|
if (isXS || !me) return null
|
2020-05-13 01:36:54 +01:00
|
|
|
|
2020-03-11 23:56:18 +00:00
|
|
|
const content = !account ? null : { __html: account.get('note_emojified') }
|
2020-04-23 07:13:29 +01:00
|
|
|
const to = !account ? '' : `/${account.get('acct')}`
|
2020-03-11 23:56:18 +00:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
return (
|
2020-04-23 07:13:29 +01:00
|
|
|
<PopoverLayout width={280}>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.px15, _s.py15].join(' ')} id='user-info-popover'>
|
2020-03-11 23:56:18 +00:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow].join(' ')}>
|
2020-04-23 07:13:29 +01:00
|
|
|
<NavLink
|
|
|
|
to={to}
|
2020-08-18 21:49:11 +01:00
|
|
|
className={[_s.d, _s.noUnderline, _s.flexGrow1].join(' ')}
|
2020-04-23 07:13:29 +01:00
|
|
|
>
|
2020-04-24 04:17:27 +01:00
|
|
|
<Avatar account={account} size={42} noHover />
|
|
|
|
<DisplayName account={account} isMultiline noHover />
|
2020-04-23 07:13:29 +01:00
|
|
|
</NavLink>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mlAuto, _s.right0, _s.posAbs, _s.mt5].join(' ')}>
|
2020-04-23 07:13:29 +01:00
|
|
|
<AccountActionButton account={account} />
|
2020-03-11 23:56:18 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mt10].join(' ')}>
|
2020-03-11 23:56:18 +00:00
|
|
|
<div className={_s.dangerousContent} dangerouslySetInnerHTML={content} />
|
|
|
|
</div>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.mt10].join(' ')}>
|
2020-12-17 06:34:00 +00:00
|
|
|
<UserStat
|
|
|
|
title={<FormattedMessage id='account.followers' defaultMessage='Followers' />}
|
|
|
|
value={shortNumberFormat(account.get('followers_count'))}
|
|
|
|
to={`/${account.get('acct')}/followers`}
|
|
|
|
isInline
|
|
|
|
/>
|
|
|
|
<UserStat
|
|
|
|
isLast
|
|
|
|
title={<FormattedMessage id='account.follows' defaultMessage='Following' />}
|
|
|
|
value={shortNumberFormat(account.get('following_count'))}
|
|
|
|
to={`/${account.get('acct')}/following`}
|
|
|
|
isInline
|
|
|
|
/>
|
2020-06-13 00:37:14 +01:00
|
|
|
</div>
|
|
|
|
|
2020-03-11 23:56:18 +00:00
|
|
|
</div>
|
2020-02-28 15:20:47 +00:00
|
|
|
</PopoverLayout>
|
|
|
|
)
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
|
|
|
account: makeGetAccount()(state, props.accountId),
|
|
|
|
})
|
|
|
|
|
2021-01-09 08:25:54 +00:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onFetchRelationships(accountId) {
|
|
|
|
dispatch(fetchRelationships([accountId]))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
UserInfoPopover.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
accountId: PropTypes.string.isRequired,
|
|
|
|
isXS: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
2021-01-09 08:25:54 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(UserInfoPopover)
|