pleroma/app/gabsocial/features/status/components/status_interaction_bar.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-05-19 20:54:05 -07:00
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import emojify from 'gabsocial/features/emoji/emoji';
2020-05-20 09:46:49 -07:00
import { reduceEmoji } from 'gabsocial/utils/emoji_reacts';
2020-05-22 16:44:24 -07:00
import SoapboxPropTypes from 'gabsocial/utils/soapbox_prop_types';
2020-05-19 20:54:05 -07:00
export class StatusInteractionBar extends React.Component {
2020-05-21 22:08:55 -07:00
static propTypes = {
2020-05-19 20:54:05 -07:00
status: ImmutablePropTypes.map,
2020-05-22 16:44:24 -07:00
me: SoapboxPropTypes.me,
2020-05-19 20:54:05 -07:00
}
2020-05-20 11:11:44 -07:00
getNormalizedReacts = () => {
2020-05-22 16:44:24 -07:00
const { status, me } = this.props;
2020-05-19 20:54:05 -07:00
const emojiReacts = status.getIn(['pleroma', 'emoji_reactions']);
2020-05-20 09:46:49 -07:00
const favouritesCount = status.get('favourites_count');
2020-05-22 16:44:24 -07:00
return reduceEmoji(emojiReacts, favouritesCount, me).reverse();
2020-05-20 11:11:44 -07:00
}
render() {
const emojiReacts = this.getNormalizedReacts();
const count = emojiReacts.reduce((acc, cur) => (
acc + cur.get('count')
), 0);
const EmojiReactsContainer = () => (
2020-05-20 11:11:44 -07:00
<div className='emoji-reacts-container'>
<div className='emoji-reacts'>
{emojiReacts.map((e, i) => (
<span className='emoji-react' key={i}>
<span
className='emoji-react__emoji'
dangerouslySetInnerHTML={{ __html: emojify(e.get('name')) }}
/>
<span className='emoji-react__count'>{e.get('count')}</span>
</span>
))}
</div>
<div className='emoji-reacts__count'>
{count}
</div>
2020-05-20 09:46:49 -07:00
</div>
2020-05-19 20:54:05 -07:00
);
return (
<div className='status-interaction-bar'>
{count > 0 && <EmojiReactsContainer />}
</div>
);
2020-05-19 20:54:05 -07:00
}
}