-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebar.js
70 lines (59 loc) · 2.05 KB
/
Sidebar.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
import React, {useEffect, useState } from 'react';
import "./Sidebar.css";
import DonutLargeIcon from '@material-ui/icons/DonutLarge';
import { Avatar, IconButton } from '@material-ui/core';
import ChatIcon from '@material-ui/icons/Chat';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import SearchIcon from '@material-ui/icons/Search';
import SidebarChat from './SidebarChat';
import db from "./firebase";
import { useStateValue } from './StateProvider';
function Sidebar() {
const[rooms,setRooms]=useState([]);
const [{user},dispatch]=useStateValue();
useEffect(() => {
const unsubscribe =db.collection("rooms").onSnapshot((snapshot) =>
setRooms(snapshot.docs.map((doc) =>
({
id:doc.id,
data:doc.data(),
}))
)
)
return() =>{
unsubscribe();
}
}, []);
return (
<div className="sidebar">
<div className="sidebar__header">
<Avatar src={user?.photoURL}/>
<div className="sidebar__headerRight">
<IconButton>
<DonutLargeIcon/>
</IconButton>
<IconButton>
<ChatIcon/>
</IconButton>
<IconButton>
<MoreVertIcon/>
</IconButton>
</div>
</div>
<div className="sidebar__search">
<div className="sidebar__searchContainer">
<SearchIcon/>
<input placeholder="Search or Start for new chat"/>
</div>
</div>
<div className="sidebar__chats">
<SidebarChat addNewChat/>
{rooms.map(room=>(
<SidebarChat key={room.id} id={room.id}
name={room.data.name} />
))}
</div>
</div>
)
}
export default Sidebar