bigbuffet-rw/app/soapbox/features/status/components/status_interaction_bar.js

77 lines
2.2 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 { FormattedNumber } from 'react-intl';
2020-05-28 15:52:07 -07:00
import emojify from 'soapbox/features/emoji/emoji';
import { reduceEmoji } from 'soapbox/utils/emoji_reacts';
import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types';
import { Link } from 'react-router-dom';
import Icon from 'soapbox/components/icon';
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 = () => {
const { status } = this.props;
return reduceEmoji(
status.getIn(['pleroma', 'emoji_reactions']),
status.get('favourites_count'),
status.get('favourited'),
).reverse();
2020-05-20 11:11:44 -07:00
}
getRepost = () => {
const { status } = this.props;
if (status.get('reblogs_count')) {
return (
2020-07-08 19:42:34 -07:00
<Link to={`/@${status.getIn(['account', 'acct'])}/posts/${status.get('id')}/reblogs`} className='emoji-react emoji-react--reblogs'>
<Icon id='retweet' />
2020-07-08 19:42:34 -07:00
<span className='emoji-reacts__count'>
<FormattedNumber value={status.get('reblogs_count')} />
</span>
</Link>
);
}
return '';
}
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 repost = this.getRepost();
2020-05-20 11:11:44 -07:00
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 />}
{repost}
</div>
);
2020-05-19 20:54:05 -07:00
}
}