-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavBar.js
64 lines (63 loc) · 2.47 KB
/
NavBar.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
import React, { useState } from "react";
import ChatLink from "./ChatLinks.js";
import NewChatForm from "./NewChatForm.js";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSlidersH } from "@fortawesome/free-solid-svg-icons";
import { Link, useParams } from "react-router-dom";
import { addChatAction, deleteChatAction } from "./Chat.js";
import { useSelector, useDispatch } from "react-redux";
export default function NavBar() {
const state = useSelector(state => state);
const [navState, setNavState] = useState({show: true});
const dispatch = useDispatch();
const keys = Object.keys(state);
const handleState = () => {
setNavState((prevState) => {
return{
show: !prevState.show
}
});
};
return(
<nav className="nav">
{
navState.show
? <>
<NewChatForm dispatch={dispatch}/>
<fieldset style={{borderRadius: "1rem", border: "1px solid lightgrey", fontFamily: "Poppins"}}>
<legend>Direct Messages</legend>
<div className="dms">
{
keys.map((key) => {
return(
<section style={{
marginBottom: "2.5rem"
}}>
<p className="chat-link-title">{state[key].title}</p>
<ChatLink message={state[key].textInfo.slice(-1)[0].text} pic={
state[key].textInfo.slice(-1)[0].isFrom === "BOT"
? state[key].people[0].pic
: state[key].people[1].pic
}
name={
state[key].textInfo.slice(-1)[0].isFrom === "BOT"
? state[key].people[0].name
: state[key].people[1].name
}/><br/>
<span onClick={() => {
const canDelete = confirm("Do you want to delete this chat?");
canDelete && dispatch(deleteChatAction(key));
}} className="delete-chat">Delete Chat</span> <span><Link to={`/${key}`} className="enter-chat">Enter</Link></span>
</section>
);
})
}
</div>
</fieldset>
<br /><span onClick={handleState} className="nav-close">Close Nav Bar<img/></span>
</>
: <button className="nav-open" onClick={handleState}><FontAwesomeIcon icon={faSlidersH} size="7x"/></button>
}
</nav>
);
}