-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
index.tsx
54 lines (46 loc) · 1.46 KB
/
index.tsx
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
import React from 'react'
import classNames from 'classnames'
import useDialog from '../../hooks/dialog/useDialog'
import ReactionsDialog from '../dialogs/ReactionsDialog'
import styles from './styles.module.scss'
import type { T } from '@deltachat/jsonrpc-client'
// With this constant we define how many max. different emojis we display
// under each message.
//
// Reactions are sorted by their frequencies in the core, that is, the
// most used emojis come first in this list.
const SHOW_MAX_DIFFERENT_EMOJIS = 5
type Props = {
reactions: T.Reactions
}
export default function Reactions(props: Props) {
const { openDialog } = useDialog()
const { reactionsByContact, reactions } = props.reactions
const handleClick = () => {
openDialog(ReactionsDialog, {
reactionsByContact,
})
}
return (
<div className={styles.reactions} onClick={handleClick}>
{reactions
.slice(0, SHOW_MAX_DIFFERENT_EMOJIS)
.map(({ emoji, isFromSelf, count }) => {
return (
<span
className={classNames(styles.emoji, {
[styles.isFromSelf]: isFromSelf,
})}
key={emoji}
>
{emoji}
{count > 1 && <span className={styles.emojiCount}>{count}</span>}
</span>
)
})}
{reactions.length > SHOW_MAX_DIFFERENT_EMOJIS && (
<span className={classNames(styles.emoji, styles.showMore)} />
)}
</div>
)
}