-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathNavBar.jsx
165 lines (150 loc) · 4.71 KB
/
NavBar.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { useMemo } from 'react';
import { NavLink, useLocation } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Tooltip, Whisper } from 'rsuite';
import { Icon } from '@iconify/react';
import { useKindeAuth } from '@kinde-oss/kinde-auth-react';
// Store
import { useDialog } from 'src/context/DialogContext';
import { useAuth } from 'context/AuthContext';
import { socket } from 'src/lib/socketConnection';
// Lib
import { useApp } from 'src/context/AppContext';
import { NEW_EVENT_LOGOUT } from '../../../constants.json';
const linkStyle = `h-full w-full flex items-center justify-center hover:bg-primary rounded-[15px] md:max-h-[60px] md:h-[60px] md:min-h-[60px] `;
const activeStyle = linkStyle + 'bg-primary';
const NavBar = () => {
const { authState, dispatchAuth } = useAuth();
const { logout } = useKindeAuth();
const { app } = useApp();
const location = useLocation();
const { setDialog } = useDialog();
function logOut() {
dispatchAuth({
type: 'LOGOUT',
});
logout();
}
const handleLogout = () => {
setDialog({
isOpen: true,
text: 'Are you sure you want to logout?',
noBtnText: 'Cancel',
yesBtnText: 'Yes, log me out',
handler: () => {
if (socket.disconnected) {
socket.volatile.emit(NEW_EVENT_LOGOUT, {
email: authState.email,
loginId: authState.loginId,
});
} else {
socket.emit(NEW_EVENT_LOGOUT, {
email: authState.email,
loginId: authState.loginId,
});
}
logOut();
},
});
};
const getLinkStyle = ({ isActive }) => (isActive ? activeStyle : linkStyle);
const fullscreenPages = ['/founduser'];
const hideNavbar = useMemo(
() => fullscreenPages.includes(location.pathname) && app.currentChatId,
[location, app]
);
return (
<div
className={`${
hideNavbar && 'hidden'
} bg-secondary md:w-[120px] md:min-h-screen md:max-h-screen items-center md:flex-col flex-row justify-between shadow-[rgb(0,_0,_0)_12px_0px_18px_-18px] p-2 md:p-5 sticky bottom-0 md:flex max-h-[70px] h-[70px] min-h-[70px]`}
>
<div className="hidden md:flex">
<img src="favicon.ico" />
</div>
<div className="justify-between md:justify-center flex items-center md:flex-col flex-row w-full gap-2 flex-nowrap overflow-auto">
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Search for random buddies</Tooltip>}
>
<NavLink to="/" className={getLinkStyle}>
<Icon icon="fluent:people-search-20-regular" color="white" height="24" width="24" />
</NavLink>
</Whisper>
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Friends</Tooltip>}
>
<NavLink to="/friends" className={getLinkStyle}>
<Icon color="white" icon="la:user-friends" height="24" width="24" />
</NavLink>
</Whisper>
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>My Profile</Tooltip>}
>
<NavLink to="/profile" className={getLinkStyle}>
<Icon icon="fluent:person-circle-20-regular" color="white" height="24" width="24" />
</NavLink>
</Whisper>
{/* show only on mobile screen */}
<div className="flex w-full md:hidden h-full">
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Settings</Tooltip>}
>
<NavLink to="/settings" className={getLinkStyle}>
<Icon icon="ic:outline-settings" color="white" height="24" width="24" />
</NavLink>
</Whisper>
</div>
<div className="flex w-full md:hidden h-full">
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Logout</Tooltip>}
>
<button className={linkStyle} onClick={() => handleLogout()}>
<Icon icon="majesticons:logout-half-circle" color="white" height={24} width={24} />
</button>
</Whisper>
</div>
</div>
<div className="hidden md:flex w-full flex-col gap-2">
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Settings</Tooltip>}
>
<NavLink to="/settings" className={getLinkStyle}>
<Icon icon="ic:outline-settings" color="white" height="24" width="24" />
</NavLink>
</Whisper>
<Whisper
placement="auto"
controlId="control-id-hover"
trigger="hover"
speaker={<Tooltip>Logout</Tooltip>}
>
<button className={linkStyle} onClick={() => handleLogout()}>
<Icon icon="majesticons:logout-half-circle" color="white" height={24} width={24} />
</button>
</Whisper>
</div>
</div>
);
};
NavBar.propTypes = {
className: PropTypes.string,
};
export default NavBar;