// @flow import { ENABLE_CREATOR_REACTIONS } from 'config'; import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import * as REACTION_TYPES from 'constants/reactions'; import React from 'react'; import classnames from 'classnames'; import Button from 'component/button'; import ChannelThumbnail from 'component/channelThumbnail'; import { useHistory } from 'react-router'; import { useIsMobile } from 'effects/use-screensize'; import { formatNumber } from 'util/number'; type Props = { myReacts: Array, othersReacts: any, react: (string, string) => void, commentId: string, pendingCommentReacts: Array, claimIsMine: boolean, activeChannelId: ?string, uri: string, claim: ?ChannelClaim, doToast: ({ message: string }) => void, hideCreatorLike: boolean, resolve: (string) => void, }; export default function CommentReactions(props: Props) { const { myReacts, othersReacts, commentId, react, claimIsMine, uri, claim, activeChannelId, doToast, hideCreatorLike, resolve, } = props; const { push, location: { pathname }, } = useHistory(); const isMobile = useIsMobile(); React.useEffect(() => { if (!claim) { resolve(uri); } }, [claim, resolve, uri]); const canCreatorReact = claim && claimIsMine && (claim.value_type === 'channel' ? claim.claim_id === activeChannelId : claim.signing_channel && claim.signing_channel.claim_id === activeChannelId); const authorUri = claim && claim.value_type === 'channel' ? claim.canonical_url : claim && claim.signing_channel && claim.signing_channel.canonical_url; const getCountForReact = (type) => { let count = 0; if (othersReacts && othersReacts[type]) { count += othersReacts[type]; } if (myReacts && myReacts.includes(type)) { count += 1; } return count; }; const shouldHide = !canCreatorReact && hideCreatorLike; const creatorLiked = getCountForReact(REACTION_TYPES.CREATOR_LIKE) > 0; const likeIcon = ICONS.UPVOTE; const dislikeIcon = ICONS.DOWNVOTE; function handleCommentLike() { if (activeChannelId) { react(commentId, REACTION_TYPES.LIKE); } else { promptForChannel(); } } function handleCommentDislike() { if (activeChannelId) { react(commentId, REACTION_TYPES.DISLIKE); } else { promptForChannel(); } } function promptForChannel() { push(`/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}&lc=${commentId}`); doToast({ message: __('A channel is required to throw fire and slime') }); } return ( <> )} ); }