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

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-02-28 15:20:47 +00:00
import { defineMessages, injectIntl } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import { me, favouritesCount } from '../../initial_state'
2020-02-28 15:20:47 +00:00
import { shortNumberFormat } from '../../utils/numbers'
import PanelLayout from './panel_layout'
import UserStat from '../user_stat'
2020-05-09 03:17:19 +01:00
import Dummy from '../dummy'
import ResponsiveClassesComponent from '../../features/ui/util/responsive_classes_component'
2020-02-28 15:20:47 +00:00
const messages = defineMessages({
gabs: { id: 'account.gabs', defaultMessage: 'Gabs' },
followers: { id: 'account.followers', defaultMessage: 'Followers' },
follows: { id: 'account.follows', defaultMessage: 'Follows' },
2020-03-24 04:39:12 +00:00
likes: { id: 'likes', defaultMessage: 'Likes' },
2020-02-28 15:20:47 +00:00
})
export default
@injectIntl
class ProfileStatsPanel extends ImmutablePureComponent {
static propTypes = {
2020-03-24 04:39:12 +00:00
account: ImmutablePropTypes.map,
2020-02-28 15:20:47 +00:00
intl: PropTypes.object.isRequired,
2020-05-09 03:17:19 +01:00
noPanel: PropTypes.bool,
2020-02-28 15:20:47 +00:00
}
render() {
2020-05-09 03:17:19 +01:00
const {
intl,
account,
noPanel
} = this.props
2020-02-28 15:20:47 +00:00
if (!account) return null
2020-05-09 03:17:19 +01:00
const Wrapper = noPanel ? Dummy : PanelLayout
2020-02-28 15:20:47 +00:00
return (
2020-05-09 03:17:19 +01:00
<Wrapper>
2020-02-28 15:20:47 +00:00
{
!!account &&
2020-05-09 03:17:19 +01:00
<ResponsiveClassesComponent
classNames={[_s.default, _s.flexRow].join(' ')}
classNamesXS={[_s.default, _s.flexRow, _s.mt15, _s.pt10].join(' ')}
>
2020-02-28 15:20:47 +00:00
<UserStat
title={intl.formatMessage(messages.gabs)}
value={shortNumberFormat(account.get('statuses_count'))}
to={`/${account.get('acct')}`}
2020-05-09 03:17:19 +01:00
isCentered={noPanel}
2020-02-28 15:20:47 +00:00
/>
<UserStat
title={intl.formatMessage(messages.followers)}
value={shortNumberFormat(account.get('followers_count'))}
to={`/${account.get('acct')}/followers`}
2020-05-09 03:17:19 +01:00
isCentered={noPanel}
2020-02-28 15:20:47 +00:00
/>
<UserStat
title={intl.formatMessage(messages.follows)}
value={shortNumberFormat(account.get('following_count'))}
to={`/${account.get('acct')}/following`}
isCentered={noPanel}
/>
2020-02-28 15:20:47 +00:00
{
account.get('id') === me &&
<UserStat
2020-03-24 04:39:12 +00:00
title={intl.formatMessage(messages.likes)}
value={shortNumberFormat(favouritesCount)}
2020-03-24 04:39:12 +00:00
to={`/${account.get('acct')}/likes`}
2020-05-09 03:17:19 +01:00
isCentered={noPanel}
2020-02-28 15:20:47 +00:00
/>
}
2020-05-09 03:17:19 +01:00
</ResponsiveClassesComponent>
2020-02-28 15:20:47 +00:00
}
2020-05-09 03:17:19 +01:00
</Wrapper>
2020-02-28 15:20:47 +00:00
)
}
}