2020-10-02 21:18:53 +02:00
|
|
|
// @flow
|
2021-03-03 20:23:42 +01: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';
|
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';
|
2020-10-02 21:18:53 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
claim: StreamClaim,
|
2021-03-03 20:23:42 +01:00
|
|
|
doFetchReactions: (string) => void,
|
|
|
|
doReactionLike: (string) => void,
|
|
|
|
doReactionDislike: (string) => void,
|
2020-10-02 21:18:53 +02:00
|
|
|
uri: string,
|
|
|
|
likeCount: number,
|
|
|
|
dislikeCount: number,
|
|
|
|
myReaction: ?string,
|
2021-03-03 20:23:42 +01:00
|
|
|
livestream?: boolean,
|
2020-10-02 21:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function FileReactions(props: Props) {
|
2021-03-03 20:23:42 +01:00
|
|
|
const {
|
|
|
|
claim,
|
|
|
|
uri,
|
|
|
|
doFetchReactions,
|
|
|
|
doReactionLike,
|
|
|
|
doReactionDislike,
|
|
|
|
myReaction,
|
|
|
|
likeCount,
|
|
|
|
dislikeCount,
|
|
|
|
livestream,
|
|
|
|
} = props;
|
2020-10-02 21:18:53 +02:00
|
|
|
const claimId = claim && claim.claim_id;
|
2020-11-17 20:10:14 +01:00
|
|
|
const channel = claim && claim.signing_channel && claim.signing_channel.name;
|
2020-10-02 21:18:53 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
2021-03-03 20:23:42 +01:00
|
|
|
function fetchReactions() {
|
2020-10-02 21:18:53 +02:00
|
|
|
doFetchReactions(claimId);
|
|
|
|
}
|
2021-03-03 20:23:42 +01:00
|
|
|
|
|
|
|
let fetchInterval;
|
|
|
|
if (claimId) {
|
|
|
|
fetchReactions();
|
|
|
|
|
|
|
|
if (livestream) {
|
|
|
|
fetchInterval = setInterval(fetchReactions, 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
if (fetchInterval) {
|
|
|
|
clearInterval(fetchInterval);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}, [claimId, doFetchReactions, livestream]);
|
2020-10-02 21:18:53 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-11-17 20:10:14 +01:00
|
|
|
{channel && (
|
|
|
|
<NudgeFloating
|
|
|
|
name="nudge:support-acknowledge"
|
|
|
|
text={__('Let %channel% know you enjoyed this!', { channel })}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2020-10-02 21:18:53 +02:00
|
|
|
<Button
|
|
|
|
title={__('I like this')}
|
2020-11-17 20:10:14 +01:00
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
authSrc="filereaction_like"
|
2021-03-03 20:23:42 +01:00
|
|
|
className={classnames('button--file-action', { 'button--fire': myReaction === REACTION_TYPES.LIKE })}
|
|
|
|
label={
|
|
|
|
<>
|
|
|
|
{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)}
|
|
|
|
</>
|
|
|
|
}
|
2020-10-02 21:18:53 +02:00
|
|
|
iconSize={18}
|
2021-03-03 20:23:42 +01:00
|
|
|
icon={myReaction === REACTION_TYPES.LIKE ? ICONS.FIRE_ACTIVE : ICONS.FIRE}
|
2020-10-02 21:18:53 +02:00
|
|
|
onClick={() => doReactionLike(uri)}
|
|
|
|
/>
|
|
|
|
<Button
|
2020-11-17 20:10:14 +01:00
|
|
|
requiresAuth={IS_WEB}
|
|
|
|
authSrc={'filereaction_dislike'}
|
2020-10-02 21:18:53 +02:00
|
|
|
title={__('I dislike this')}
|
2021-03-03 20:23:42 +01:00
|
|
|
className={classnames('button--file-action', { 'button--slime': myReaction === REACTION_TYPES.DISLIKE })}
|
|
|
|
label={
|
|
|
|
<>
|
|
|
|
{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
|
|
|
iconSize={18}
|
2021-03-03 20:23:42 +01:00
|
|
|
icon={myReaction === REACTION_TYPES.DISLIKE ? ICONS.SLIME_ACTIVE : ICONS.SLIME}
|
2020-10-02 21:18:53 +02:00
|
|
|
onClick={() => doReactionDislike(uri)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileReactions;
|