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-02-19 23:57:07 +00:00
|
|
|
import { NavLink } from 'react-router-dom'
|
|
|
|
import { injectIntl, defineMessages } from 'react-intl'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-02-28 15:20:47 +00:00
|
|
|
import { me } from '../../initial_state'
|
2020-02-19 23:57:07 +00:00
|
|
|
import { makeGetAccount } from '../../selectors'
|
|
|
|
import { shortNumberFormat } from '../../utils/numbers'
|
2020-04-23 07:13:29 +01:00
|
|
|
import { openModal } from '../../actions/modal'
|
2020-04-29 23:32:49 +01:00
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
MODAL_EDIT_PROFILE,
|
2020-12-30 17:20:39 +00:00
|
|
|
PLACEHOLDER_MISSING_HEADER_SRC,
|
2020-04-29 23:32:49 +01:00
|
|
|
} from '../../constants'
|
|
|
|
import PanelLayout from './panel_layout'
|
|
|
|
import Avatar from '../avatar'
|
2020-03-24 04:39:12 +00:00
|
|
|
import Button from '../button'
|
2020-02-19 23:57:07 +00:00
|
|
|
import DisplayName from '../display_name'
|
|
|
|
import Image from '../image'
|
|
|
|
import UserStat from '../user_stat'
|
2020-03-24 04:39:12 +00:00
|
|
|
|
2020-02-19 23:57:07 +00:00
|
|
|
class UserPanel extends ImmutablePureComponent {
|
2020-04-29 23:32:49 +01:00
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
state = {
|
|
|
|
hovering: false,
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:13:29 +01:00
|
|
|
updateOnProps = [
|
|
|
|
'account'
|
|
|
|
]
|
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
handleOnMouseEnter = () => {
|
|
|
|
this.setState({ hovering: true })
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnMouseLeave = () => {
|
|
|
|
this.setState({ hovering: false })
|
|
|
|
}
|
|
|
|
|
2020-07-17 21:25:05 +01:00
|
|
|
handleOnEditProfile = () => {
|
|
|
|
this.props.onOpenEditProfile()
|
|
|
|
}
|
|
|
|
|
2020-02-19 23:57:07 +00:00
|
|
|
render() {
|
2020-04-29 23:32:49 +01:00
|
|
|
const {
|
|
|
|
account,
|
|
|
|
intl,
|
|
|
|
onOpenEditProfile,
|
|
|
|
} = this.props
|
2020-03-24 04:39:12 +00:00
|
|
|
const { hovering } = this.state
|
|
|
|
|
2020-12-30 17:20:39 +00:00
|
|
|
const acct = account.get('acct')
|
|
|
|
const headerSrc = !!account ? account.get('header') : undefined
|
|
|
|
const headerMissing = !headerSrc ? true : headerSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
const buttonClasses = CX({
|
2020-04-23 07:13:29 +01:00
|
|
|
posAbs: 1,
|
2020-03-24 04:39:12 +00:00
|
|
|
mr10: 1,
|
|
|
|
top0: 1,
|
|
|
|
right0: 1,
|
2020-12-30 17:20:39 +00:00
|
|
|
mt10: 1,
|
2020-03-24 04:39:12 +00:00
|
|
|
displayNone: !hovering,
|
|
|
|
})
|
2020-02-19 23:57:07 +00:00
|
|
|
|
2020-12-30 17:20:39 +00:00
|
|
|
const headerContainerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
h122PX: !headerMissing,
|
|
|
|
h55PX: headerMissing,
|
|
|
|
bgSecondary: headerMissing,
|
|
|
|
})
|
2020-04-23 07:13:29 +01:00
|
|
|
|
2020-02-19 23:57:07 +00:00
|
|
|
return (
|
|
|
|
<PanelLayout noPadding>
|
2020-03-24 04:39:12 +00:00
|
|
|
<div
|
2020-12-30 17:20:39 +00:00
|
|
|
className={headerContainerClasses}
|
2020-04-23 07:13:29 +01:00
|
|
|
onMouseEnter={this.handleOnMouseEnter}
|
|
|
|
onMouseLeave={this.handleOnMouseLeave}
|
2020-03-24 04:39:12 +00:00
|
|
|
>
|
2020-12-30 17:20:39 +00:00
|
|
|
{
|
|
|
|
!headerMissing &&
|
|
|
|
<Image
|
|
|
|
alt={intl.formatMessage(messages.headerPhoto)}
|
|
|
|
className={_s.h122PX}
|
|
|
|
src={account.get('header_static')}
|
|
|
|
/>
|
|
|
|
}
|
2020-03-24 04:39:12 +00:00
|
|
|
<Button
|
|
|
|
color='secondary'
|
|
|
|
backgroundColor='secondary'
|
|
|
|
radiusSmall
|
|
|
|
className={buttonClasses}
|
2020-07-17 21:25:05 +01:00
|
|
|
onClick={this.handleOnEditProfile}
|
2020-03-24 04:39:12 +00:00
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.edit_profile)}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2020-02-19 23:57:07 +00:00
|
|
|
|
|
|
|
<NavLink
|
2020-08-18 21:49:11 +01:00
|
|
|
className={[_s.d, _s.flexRow, _s.py10, _s.px15, _s.noUnderline].join(' ')}
|
2020-04-23 07:13:29 +01:00
|
|
|
to={`/${acct}`}
|
2020-02-19 23:57:07 +00:00
|
|
|
>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mtNeg32PX, _s.circle, _s.borderColorPrimary, _s.border6PX].join(' ')}>
|
2020-04-24 04:17:27 +01:00
|
|
|
<Avatar account={account} size={62} noHover />
|
2020-02-19 23:57:07 +00:00
|
|
|
</div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.ml15].join(' ')}>
|
2020-04-24 04:17:27 +01:00
|
|
|
<DisplayName account={account} isMultiline noRelationship noHover />
|
2020-02-19 23:57:07 +00:00
|
|
|
</div>
|
|
|
|
</NavLink>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mb15, _s.mt5, _s.flexRow, _s.px15].join(' ')}>
|
2020-02-28 15:20:47 +00:00
|
|
|
<UserStat
|
2020-04-23 07:13:29 +01:00
|
|
|
to={`/${acct}`}
|
2020-02-28 15:20:47 +00:00
|
|
|
title={intl.formatMessage(messages.gabs)}
|
|
|
|
value={shortNumberFormat(account.get('statuses_count'))}
|
|
|
|
/>
|
|
|
|
<UserStat
|
2020-04-23 07:13:29 +01:00
|
|
|
to={`/${acct}/followers`}
|
2020-02-28 15:20:47 +00:00
|
|
|
title={intl.formatMessage(messages.followers)}
|
|
|
|
value={shortNumberFormat(account.get('followers_count'))}
|
|
|
|
/>
|
|
|
|
<UserStat
|
2020-04-23 07:13:29 +01:00
|
|
|
to={`/${acct}/following`}
|
2020-02-28 15:20:47 +00:00
|
|
|
title={intl.formatMessage(messages.follows)}
|
|
|
|
value={shortNumberFormat(account.get('following_count'))}
|
|
|
|
/>
|
2020-02-19 23:57:07 +00:00
|
|
|
</div>
|
|
|
|
</PanelLayout>
|
|
|
|
)
|
|
|
|
}
|
2020-04-29 23:32:49 +01:00
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
gabs: { id: 'account.posts', defaultMessage: 'Gabs' },
|
|
|
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
|
|
|
follows: { id: 'account.follows', defaultMessage: 'Following' },
|
|
|
|
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
|
|
|
|
headerPhoto: { id: 'header_photo', defaultMessage: 'Header photo' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
account: makeGetAccount()(state, me),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onOpenEditProfile() {
|
|
|
|
dispatch(openModal(MODAL_EDIT_PROFILE))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
UserPanel.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onOpenEditProfile: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(UserPanel))
|