import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { connect } from 'react-redux'; import { FormattedNumber } from 'react-intl'; import emojify from 'soapbox/features/emoji/emoji'; import { reduceEmoji } from 'soapbox/utils/emoji_reacts'; import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types'; import { getFeatures } from 'soapbox/utils/features'; import { Link } from 'react-router-dom'; import Icon from 'soapbox/components/icon'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; const mapStateToProps = state => { const instance = state.get('instance'); return { allowedEmoji: getSoapboxConfig(state).get('allowedEmoji'), features: getFeatures(instance), }; }; export default @connect(mapStateToProps) class StatusInteractionBar extends ImmutablePureComponent { static propTypes = { status: ImmutablePropTypes.map, me: SoapboxPropTypes.me, allowedEmoji: ImmutablePropTypes.list, features: PropTypes.object.isRequired, } getNormalizedReacts = () => { const { status } = this.props; return reduceEmoji( status.getIn(['pleroma', 'emoji_reactions']), status.get('favourites_count'), status.get('favourited'), this.props.allowedEmoji, ).reverse(); } getReposts = () => { const { status } = this.props; if (status.get('reblogs_count')) { return ( ); } return ''; } getFavourites = () => { const { features, status } = this.props; if (status.get('favourites_count')) { const favourites = ( <> ); if (features.exposableReactions) { return ( {favourites} ); } else { return (
{favourites}
); } } return ''; } getEmojiReacts = () => { const { status, features } = this.props; const emojiReacts = this.getNormalizedReacts(); const count = emojiReacts.reduce((acc, cur) => ( acc + cur.get('count') ), 0); if (count > 0) { return (
{emojiReacts.map((e, i) => { const emojiReact = ( <> {e.get('count')} ); if (features.exposableReactions) { return {emojiReact}; } return {emojiReact}; })}
{count}
); } return ''; }; render() { const { features } = this.props; return (
{features.emojiReacts ? this.getEmojiReacts() : this.getFavourites()} {this.getReposts()}
); } }