-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageForm.jsx
59 lines (49 loc) · 1.47 KB
/
MessageForm.jsx
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
import { useState } from 'react';
import { SendOutlined, PictureOutlined } from '@ant-design/icons';
import { sendMessage, isTyping } from 'react-chat-engine';
const MessageForm = (props) => {
const [value, setValue] = useState('');
const { chatId, creds } = props;
const handleChange = (event) => {
setValue(event.target.value);
isTyping(props, chatId);
};
const handleSubmit = (event) => {
event.preventDefault();
const text = value.trim();
if (text.length > 0) {
sendMessage(creds, chatId, { text });
}
setValue('');
};
const handleUpload = (event) => {
sendMessage(creds, chatId, { files: event.target.files, text: '' });
};
return (
<form className="message-form" onSubmit={handleSubmit}>
<input
className="message-input"
placeholder="Send a message..."
value={value}
onChange={handleChange}
onSubmit={handleSubmit}
/>
<label htmlFor="upload-button">
<span className="image-button">
<PictureOutlined className="picture-icon" />
</span>
</label>
<input
type="file"
multiple={false}
id="upload-button"
style={{ display: 'none' }}
onChange={handleUpload.bind(this)}
/>
<button type="submit" className="send-button">
<SendOutlined className="send-icon" />
</button>
</form>
);
};
export default MessageForm;