-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
index.tsx
58 lines (52 loc) · 1.45 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
55
56
57
58
import * as React from 'react';
import BubbleGroupInterface from './interface';
import DefaultChatBubble from '../ChatBubble';
import Message from '../Message';
import styles from './styles';
export default class BubbleGroup extends React.Component {
props;
constructor(props: BubbleGroupInterface) {
super(props);
}
/**
* Parses and collects messages of one type to be grouped together.
* @return {messageNodes} - a JSX wrapped group of messages
*/
renderGroup(messages: [Message], id: number) {
const {
bubblesCentered,
bubbleStyles,
showSenderName,
chatBubble,
senderName,
} = this.props;
const ChatBubble = chatBubble || DefaultChatBubble;
const sampleMessage = messages[0];
const messageNodes = messages.map((message, i) => {
return (
<ChatBubble
key={i}
message={message}
bubblesCentered={bubblesCentered}
bubbleStyles={bubbleStyles}
/>
);
});
return (
<div style={styles.chatbubbleWrapper}>
{showSenderName &&
((senderName || sampleMessage.senderName) !== '' &&
(sampleMessage.id !== 0 && (
<h5 style={styles.bubbleGroupHeader}>
{senderName || sampleMessage.senderName}
</h5>
)))}
{messageNodes}
</div>
);
}
render() {
const { messages, id } = this.props;
return this.renderGroup(messages, id);
}
}