gab-social/app/javascript/gabsocial/components/panel/user_panel.js

140 lines
3.9 KiB
JavaScript
Raw Normal View History

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,
} 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
const messages = defineMessages({
gabs: { id: 'account.posts', defaultMessage: 'Gabs' },
followers: { id: 'account.followers', defaultMessage: 'Followers' },
2020-03-24 04:39:12 +00:00
follows: { id: 'account.follows', defaultMessage: 'Follows' },
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
2020-04-23 07:13:29 +01:00
headerPhoto: { id: 'header_photo', defaultMessage: 'Header photo' },
2020-02-19 23:57:07 +00:00
})
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
account: makeGetAccount()(state, me),
})
2020-02-19 23:57:07 +00:00
2020-04-23 07:13:29 +01:00
const mapDispatchToProps = (dispatch) => ({
onOpenEditProfile() {
2020-04-29 23:32:49 +01:00
dispatch(openModal(MODAL_EDIT_PROFILE))
2020-04-23 07:13:29 +01:00
},
})
2020-02-25 16:04:44 +00:00
export default
2020-04-23 07:13:29 +01:00
@connect(mapStateToProps, mapDispatchToProps)
2020-02-19 23:57:07 +00:00
@injectIntl
class UserPanel extends ImmutablePureComponent {
2020-04-29 23:32:49 +01:00
2020-02-19 23:57:07 +00:00
static propTypes = {
2020-04-23 07:13:29 +01:00
account: ImmutablePropTypes.map.isRequired,
2020-02-19 23:57:07 +00:00
intl: PropTypes.object.isRequired,
2020-04-23 07:13:29 +01:00
onOpenEditProfile: PropTypes.func.isRequired,
2020-02-19 23:57:07 +00: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-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-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
mt10: 1,
mr10: 1,
top0: 1,
right0: 1,
displayNone: !hovering,
})
2020-02-19 23:57:07 +00:00
2020-04-23 07:13:29 +01:00
const acct = account.get('acct')
2020-02-19 23:57:07 +00:00
return (
<PanelLayout noPadding>
2020-03-24 04:39:12 +00:00
<div
className={[_s.default, _s.height122PX].join(' ')}
2020-04-23 07:13:29 +01:00
onMouseEnter={this.handleOnMouseEnter}
onMouseLeave={this.handleOnMouseLeave}
2020-03-24 04:39:12 +00:00
>
<Image
2020-04-23 07:13:29 +01:00
alt={intl.formatMessage(messages.headerPhoto)}
2020-03-24 04:39:12 +00:00
className={_s.height122PX}
src={account.get('header_static')}
2020-04-11 23:29:19 +01:00
/>
2020-03-24 04:39:12 +00:00
<Button
color='secondary'
backgroundColor='secondary'
radiusSmall
className={buttonClasses}
href='/settings/profile'
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-03-11 23:56:18 +00:00
className={[_s.default, _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-04-25 18:00:51 +01:00
<div className={[_s.default, _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-03-11 23:56:18 +00:00
<div className={[_s.default, _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-03-11 23:56:18 +00:00
<div className={[_s.default, _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-02-19 23:57:07 +00:00
}