/
index.js
69 lines (63 loc) · 1.98 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
import React, {useState, useEffect} from 'react';
import {View, ActivityIndicator} from 'react-native';
import * as TalkRn from '@talkjs/react-native';
import Header from './InboxHeader';
const ConversationUI = ({
me,
other,
ID,
_height,
chatView,
}) => {
const [conversationBuilder, setConversationBuilder] = useState(null);
const [showConversationList, setShowConversationList] = useState(null);
useEffect(() => {
if (!chatView) {
setShowConversationList(true);
} else {
const builder = TalkRn.getConversationBuilder(TalkRn.oneOnOneId(me.id, other.id));
builder.setParticipant(me);
builder.setParticipant(other);
setConversationBuilder(builder);
}
}, [me, other]);
const onSelectConversation = event => {
setConversationBuilder(event.conversation);
};
const onBackPress = () => {
setShowConversationList(true);
};
return (
<>
<TalkRn.Session appId={ID} me={me}>
<View style={{height: _height}}>
{showConversationList ? (
<TalkRn.ConversationList
onSelectConversation={onSelectConversation}
loadingComponent={
<View style={{ height: _height, flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" color="#242526" />
</View>
}
/>
) : (
conversationBuilder && (
<>
<Header onBackPress={onBackPress}/>
<TalkRn.Chatbox
conversationBuilder={conversationBuilder}
loadingComponent={
<View style={{ height: _height, flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" color="#242526" />
</View>
}
/>
</>
)
)}
</View>
</TalkRn.Session>
</>
);
};
export default ConversationUI;