2020-10-02 21:18:53 +02:00
|
|
|
// @flow
|
2021-07-28 14:09:25 +02:00
|
|
|
import * as REACTION_TYPES from 'constants/reactions';
|
2020-10-02 21:18:53 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Button from 'component/button';
|
2022-02-11 19:50:55 +01:00
|
|
|
import RatioBar from 'component/ratioBar';
|
2020-10-08 18:34:48 +02:00
|
|
|
import { formatNumberWithCommas } from 'util/number';
|
2020-11-17 20:10:14 +01:00
|
|
|
import NudgeFloating from 'component/nudgeFloating';
|
2022-02-11 19:50:55 +01:00
|
|
|
// import Tooltip from 'component/common/tooltip';
|
2022-02-01 21:07:08 +01:00
|
|
|
|
|
|
|
const LIVE_REACTION_FETCH_MS = 1000 * 45;
|
2020-10-02 21:18:53 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2022-02-01 21:07:08 +01:00
|
|
|
// redux
|
|
|
|
claimId?: string,
|
|
|
|
channelName?: string,
|
|
|
|
isCollection?: boolean,
|
2020-10-02 21:18:53 +02:00
|
|
|
likeCount: number,
|
|
|
|
dislikeCount: number,
|
|
|
|
myReaction: ?string,
|
2022-02-01 21:07:08 +01:00
|
|
|
isLivestreamClaim?: boolean,
|
|
|
|
doFetchReactions: (claimId: ?string) => void,
|
|
|
|
doReactionLike: (uri: string) => void,
|
|
|
|
doReactionDislike: (uri: string) => void,
|
2020-10-02 21:18:53 +02:00
|
|
|
};
|
|
|
|
|
2022-02-01 21:07:08 +01:00
|
|
|
export default function FileReactions(props: Props) {
|
2021-07-28 14:09:25 +02:00
|
|
|
const {
|
|
|
|
uri,
|
2022-02-01 21:07:08 +01:00
|
|
|
claimId,
|
|
|
|
channelName,
|
|
|
|
isCollection,
|
2021-07-28 14:09:25 +02:00
|
|
|
myReaction,
|
|
|
|
likeCount,
|
|
|
|
dislikeCount,
|
2022-02-01 21:07:08 +01:00
|
|
|
isLivestreamClaim,
|
|
|
|
doFetchReactions,
|
|
|
|
doReactionLike,
|
|
|
|
doReactionDislike,
|
2021-07-28 14:09:25 +02:00
|
|
|
} = props;
|
|
|
|
|
2022-02-01 21:07:08 +01:00
|
|
|
const likeIcon = myReaction === REACTION_TYPES.LIKE ? ICONS.FIRE_ACTIVE : ICONS.FIRE;
|
|
|
|
const dislikeIcon = myReaction === REACTION_TYPES.DISLIKE ? ICONS.SLIME_ACTIVE : ICONS.SLIME;
|
|
|
|
|
|
|
|
const likeLabel = (
|
|
|
|
<>
|
|
|
|
{myReaction === REACTION_TYPES.LIKE && (
|
|
|
|
<>
|
|
|
|
<div className="button__fire-glow" />
|
|
|
|
<div className="button__fire-particle1" />
|
|
|
|
<div className="button__fire-particle2" />
|
|
|
|
<div className="button__fire-particle3" />
|
|
|
|
<div className="button__fire-particle4" />
|
|
|
|
<div className="button__fire-particle5" />
|
|
|
|
<div className="button__fire-particle6" />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{formatNumberWithCommas(likeCount, 0)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const dislikeLabel = (
|
|
|
|
<>
|
|
|
|
{myReaction === REACTION_TYPES.DISLIKE && (
|
|
|
|
<>
|
|
|
|
<div className="button__slime-stain" />
|
|
|
|
<div className="button__slime-drop1" />
|
|
|
|
<div className="button__slime-drop2" />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{formatNumberWithCommas(dislikeCount, 0)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2020-10-02 21:18:53 +02:00
|
|
|
React.useEffect(() => {
|
2021-07-28 14:09:25 +02:00
|
|
|
function fetchReactions() {
|
2020-10-02 21:18:53 +02:00
|
|
|
doFetchReactions(claimId);
|
|
|
|
}
|
2021-07-28 14:09:25 +02:00
|
|
|
|
|
|
|
let fetchInterval;
|
|
|
|
if (claimId) {
|
|
|
|
fetchReactions();
|
|
|
|
|
2022-02-01 21:07:08 +01:00
|
|
|
if (isLivestreamClaim) {
|
|
|
|
fetchInterval = setInterval(fetchReactions, LIVE_REACTION_FETCH_MS);
|
2021-07-28 14:09:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
if (fetchInterval) {
|
|
|
|
clearInterval(fetchInterval);
|
|
|
|
}
|
|
|
|
};
|
2022-02-01 21:07:08 +01:00
|
|
|
}, [claimId, doFetchReactions, isLivestreamClaim]);
|
2020-10-02 21:18:53 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-01 21:07:08 +01:00
|
|
|
{channelName && !isCollection && (
|
2020-11-17 20:10:14 +01:00
|
|
|
<NudgeFloating
|
|
|
|
name="nudge:support-acknowledge"
|
2022-02-01 21:07:08 +01:00
|
|
|
text={__('Let %channel% know you enjoyed this!', { channel: channelName })}
|
2020-11-17 20:10:14 +01:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2022-02-11 19:50:55 +01:00
|
|
|
<div className={'ratio-wrapper'}>
|
|
|
|
<Button
|
|
|
|
title={__('I like this')}
|
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
authSrc="filereaction_like"
|
|
|
|
className={classnames('button--file-action button-like', {
|
|
|
|
'button--fire': myReaction === REACTION_TYPES.LIKE,
|
|
|
|
})}
|
|
|
|
label={likeLabel}
|
|
|
|
iconSize={18}
|
|
|
|
icon={likeIcon}
|
|
|
|
onClick={() => doReactionLike(uri)}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
authSrc={'filereaction_dislike'}
|
|
|
|
title={__('I dislike this')}
|
|
|
|
className={classnames('button--file-action button-dislike', {
|
|
|
|
'button--slime': myReaction === REACTION_TYPES.DISLIKE,
|
|
|
|
})}
|
|
|
|
label={dislikeLabel}
|
|
|
|
iconSize={18}
|
|
|
|
icon={dislikeIcon}
|
|
|
|
onClick={() => doReactionDislike(uri)}
|
|
|
|
/>
|
|
|
|
<RatioBar likeCount={likeCount} dislikeCount={dislikeCount} />
|
|
|
|
</div>
|
2020-10-02 21:18:53 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-11 19:50:55 +01:00
|
|
|
/*
|
2022-02-01 21:07:08 +01:00
|
|
|
type ReactionProps = {
|
|
|
|
title: string,
|
|
|
|
label: any,
|
|
|
|
icon: string,
|
|
|
|
isActive: boolean,
|
|
|
|
activeClassName: string,
|
|
|
|
onClick: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
const FileReaction = (reactionProps: ReactionProps) => {
|
|
|
|
const { title, label, icon, isActive, activeClassName, onClick } = reactionProps;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip title={title} arrow={false}>
|
2022-02-02 13:45:16 +01:00
|
|
|
<div className="file-reaction__tooltip-inner">
|
2022-02-01 21:07:08 +01:00
|
|
|
<Button
|
|
|
|
requiresAuth
|
|
|
|
authSrc="filereaction_like"
|
|
|
|
className={classnames('button--file-action', { [activeClassName]: isActive })}
|
|
|
|
label={label}
|
|
|
|
iconSize={18}
|
|
|
|
icon={icon}
|
|
|
|
onClick={onClick}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
2022-02-11 19:50:55 +01:00
|
|
|
*/
|