-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.js
80 lines (74 loc) · 2.05 KB
/
index.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
// @flow
import React from 'react';
import Reaction from 'app/components/Reactions/Reaction';
import Reactions from 'app/components/Reactions';
import type { EmojiEntity } from 'app/reducers/emojis';
import type { ID } from 'app/models';
type Props = {
addReaction: ({
emoji: string,
contentTarget: string,
}) => Promise<*>,
deleteReaction: ({ reactionId: ID, contentTarget: string }) => Promise<*>,
fetchEmojis: () => Promise<*>,
fetchingEmojis: boolean,
emojis: Array<EmojiEntity>,
parentEntity: Object,
loggedIn: boolean,
};
const LegoReactions = (props: Props) => {
const {
addReaction,
deleteReaction,
emojis,
fetchEmojis,
fetchingEmojis,
parentEntity,
loggedIn,
} = props;
let mappedEmojis = [];
if (!fetchingEmojis) {
mappedEmojis = emojis.map((emoji) => {
const foundReaction =
parentEntity.reactionsGrouped &&
parentEntity.reactionsGrouped.find(
(reaction) =>
emoji.shortCode === reaction.emoji && reaction.hasReacted
);
return {
...emoji,
hasReacted: !!foundReaction,
reactionId: foundReaction ? foundReaction.reactionId : -1,
};
});
}
return (
<Reactions
emojis={mappedEmojis}
fetchEmojis={fetchEmojis}
fetchingEmojis={fetchingEmojis}
addReaction={addReaction}
deleteReaction={deleteReaction}
contentTarget={parentEntity.contentTarget}
loggedIn={loggedIn}
>
{parentEntity.reactionsGrouped.map((reaction) => {
return (
<Reaction
key={`reaction-${reaction.emoji}`}
emoji={reaction.emoji}
count={reaction.count}
unicodeString={reaction.unicodeString}
reactionId={reaction.reactionId}
hasReacted={reaction.hasReacted}
canReact={loggedIn}
addReaction={addReaction}
deleteReaction={deleteReaction}
contentTarget={parentEntity.contentTarget}
/>
);
})}
</Reactions>
);
};
export default LegoReactions;