-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathReportActionItemReactions.js
108 lines (97 loc) · 4.47 KB
/
ReportActionItemReactions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, {useRef} from 'react';
import _ from 'underscore';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
import EmojiReactionBubble from './EmojiReactionBubble';
import emojis from '../../../assets/emojis';
import AddReactionBubble from './AddReactionBubble';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../withCurrentUserPersonalDetails';
import * as Report from '../../libs/actions/Report';
import * as ReactionList from '../../pages/home/report/ReactionList/ReactionList';
import Tooltip from '../Tooltip';
import ReactionTooltipContent from './ReactionTooltipContent';
import * as EmojiUtils from '../../libs/EmojiUtils';
const propTypes = {
/**
* An array of objects containing the reaction data.
* The shape of a reaction looks like this:
*
* "reactionName": {
* emoji: string,
* users: {
* accountID: string,
* skinTone: number,
* }[]
* }
*/
// eslint-disable-next-line react/forbid-prop-types
reactions: PropTypes.arrayOf(PropTypes.object).isRequired,
/** The ID of the reportAction. It is the string representation of the a 64-bit integer. */
reportActionID: PropTypes.string.isRequired,
/**
* Function to call when the user presses on an emoji.
* This can also be an emoji the user already reacted with,
* hence this function asks to toggle the reaction by emoji.
*/
toggleReaction: PropTypes.func.isRequired,
...withCurrentUserPersonalDetailsPropTypes,
};
const defaultProps = {
...withCurrentUserPersonalDetailsDefaultProps,
};
const ReportActionItemReactions = (props) => {
const popoverReactionListAnchor = useRef(null);
const reactionsWithCount = _.filter(props.reactions, (reaction) => reaction.users.length > 0);
return (
<View
ref={popoverReactionListAnchor}
style={[styles.flexRow, styles.flexWrap, styles.gap1, styles.mt2]}
>
{_.map(reactionsWithCount, (reaction) => {
const reactionCount = reaction.users.length;
const reactionUsers = _.map(reaction.users, (sender) => sender.accountID.toString());
const emoji = _.find(emojis, (e) => e.name === reaction.emoji);
const emojiCodes = EmojiUtils.getUniqueEmojiCodes(emoji, reaction.users);
const hasUserReacted = Report.hasAccountIDReacted(props.currentUserPersonalDetails.accountID, reactionUsers);
const onPress = () => {
props.toggleReaction(emoji);
};
const onReactionListOpen = (event) => {
ReactionList.showReactionList(event, popoverReactionListAnchor.current, reaction.emoji, props.reportActionID);
};
return (
<Tooltip
renderTooltipContent={() => (
<ReactionTooltipContent
emojiName={reaction.emoji}
emojiCodes={emojiCodes}
accountIDs={reactionUsers}
currentUserPersonalDetails={props.currentUserPersonalDetails}
/>
)}
renderTooltipContentKey={[...reactionUsers, ...emojiCodes]}
key={reaction.emoji}
>
<View>
<EmojiReactionBubble
ref={props.forwardedRef}
count={reactionCount}
emojiCodes={emojiCodes}
onPress={onPress}
reactionUsers={reactionUsers}
hasUserReacted={hasUserReacted}
onReactionListOpen={onReactionListOpen}
/>
</View>
</Tooltip>
);
})}
{reactionsWithCount.length > 0 && <AddReactionBubble onSelectEmoji={props.toggleReaction} />}
</View>
);
};
ReportActionItemReactions.displayName = 'ReportActionItemReactions';
ReportActionItemReactions.propTypes = propTypes;
ReportActionItemReactions.defaultProps = defaultProps;
export default withCurrentUserPersonalDetails(ReportActionItemReactions);