-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChat.js
72 lines (64 loc) · 2.46 KB
/
Chat.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
70
71
72
import React, {useState} from 'react';
import "./Chat.css";
import {Avatar, IconButton} from "@material-ui/core";
import {AttachFile, MoreVert, SearchOutlined} from "@material-ui/icons";
import InsertEmoticonIcon from "@material-ui/icons/InsertEmoticon";
import MicIcon from "@material-ui/icons/Mic";
import axios from "./axios";
function Chat({messages}) {
const [input,setInput] = useState("");
const sendMessage = async (e) => {
e.preventDefault();
await axios.post('/messages/new', {
message: input,
name: "mayank",
timestamp: "Just now!",
received:false
});
setInput("");
}
return (
<div className="chat">
<div className="chat__header">
<Avatar />
<div className = "chat__headerInfo">
<h3>Room Name</h3>
<p>Last seen at...</p>
</div>
<div className="chat__headerRight">
<IconButton>
<SearchOutlined />
</IconButton>
<IconButton>
<AttachFile />
</IconButton>
<IconButton>
<MoreVert />
</IconButton>
</div>
</div>
<div className="chat__body">
{messages.map((message) => (
<p className={`chat__message ${message.received && "chat__receiver"}`}>
<span className="chat__name">{message.name}</span>
{message.message}
<span className="chat__timestamp">{message.timestamp}</span>
</p>
))}
</div>
<div className="chat__footer">
<IconButton>
<InsertEmoticonIcon />
</IconButton>
<form >
<input value={input} onChange = {e => setInput(e.target.value)}placeholder ="Type a message" type="text" />
<button onClick = {sendMessage} type ="submit" >Send a message</button>
</form>
<IconButton>
<MicIcon />
</IconButton>
</div>
</div>
)
}
export default Chat;