-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathInputMessage.tsx
85 lines (75 loc) · 1.74 KB
/
InputMessage.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
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
import React, { useState, useContext } from 'react';
import uuid from 'react-uuid';
import { FontAwesome } from '@expo/vector-icons';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
import { MessageType } from '../types/types';
import { DataContext } from '../context/DataProvider';
const InputMessage = () => {
const { setTextInput } = useContext<any>(DataContext);
const [text, setText] = useState<string>('');
const handleSendMessage = () => {
if (!text.trim()) return;
setTextInput({
id: uuid(),
create: new Date().getTime(),
model: 'youchat',
text: text.trim(),
user: {
name: 'you',
avatar: 'https://i.pravatar.cc/100?u=A08',
},
usage: {
prompt_tokens: 0,
completion_tokens: 0,
total_tokens: 0,
},
});
setText('');
};
return (
<View style={styles.inputMessage}>
<TextInput
style={styles.input}
onChangeText={(text) => setText(text)}
value={text}
/>
<TouchableOpacity style={styles.button} onPress={() => handleSendMessage()}>
<FontAwesome name="send" size={24} color="white" />
</TouchableOpacity>
</View>
);
};
export default InputMessage;
const styles = StyleSheet.create({
inputMessage: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
input: {
width: '75%',
height: 50,
padding: 10,
fontSize: 14,
textAlign: 'center',
color: '#ffffff',
borderColor: '#10ac84',
borderWidth: 1,
borderRadius: 5,
backgroundColor: '#222f3e',
},
button: {
flex: 0,
justifyContent: 'center',
alignItems: 'center',
width: '15%',
height: 50,
marginLeft: 10,
textAlign: 'center',
borderColor: '#10ac84',
borderWidth: 1,
borderRadius: 5,
backgroundColor: '#10ac84',
},
});