2020-10-02 21:18:53 +02:00
|
|
|
// @flow
|
|
|
|
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,
|
|
|
|
doFetchReactions: string => void,
|
|
|
|
doReactionLike: string => void,
|
|
|
|
doReactionDislike: string => void,
|
|
|
|
uri: string,
|
|
|
|
likeCount: number,
|
|
|
|
dislikeCount: number,
|
|
|
|
myReaction: ?string,
|
|
|
|
};
|
|
|
|
|
|
|
|
function FileReactions(props: Props) {
|
|
|
|
const { claim, uri, doFetchReactions, doReactionLike, doReactionDislike, likeCount, dislikeCount } = props;
|
|
|
|
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(() => {
|
|
|
|
if (claimId) {
|
|
|
|
doFetchReactions(claimId);
|
|
|
|
}
|
|
|
|
}, [claimId, doFetchReactions]);
|
|
|
|
|
|
|
|
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"
|
2020-10-02 21:18:53 +02:00
|
|
|
className={classnames('button--file-action')}
|
2021-01-12 16:25:51 +01:00
|
|
|
label={formatNumberWithCommas(likeCount, 0)}
|
2020-10-02 21:18:53 +02:00
|
|
|
iconSize={18}
|
|
|
|
icon={ICONS.UPVOTE}
|
|
|
|
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')}
|
|
|
|
className={classnames('button--file-action')}
|
2021-01-12 16:25:51 +01:00
|
|
|
label={formatNumberWithCommas(dislikeCount, 0)}
|
2020-10-02 21:18:53 +02:00
|
|
|
iconSize={18}
|
|
|
|
icon={ICONS.DOWNVOTE}
|
|
|
|
onClick={() => doReactionDislike(uri)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileReactions;
|