Skip to content

Commit 6af90c1

Browse files
committed
Updated user navbar to login, logout and open friend requests sent and friend requests recieved modals
1 parent 6f2452a commit 6af90c1

1 file changed

Lines changed: 82 additions & 6 deletions

File tree

client/src/components/ui/user_navbar.tsx

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,27 @@
22
//import "";
33

44
import Link from "next/link";
5+
import { useState } from "react";
6+
7+
import { useAuth } from "../../context/AuthContext";
8+
import UserFriendsRecieved from "../ui/popups/user_friends_recieved_popup";
9+
import UserFriendsSent from "../ui/popups/user_friends_sent_popup";
510

611
const UserNavbar = () => {
12+
const { user, logout } = useAuth();
13+
const [isModalOpen, setIsModalOpen] = useState(false);
14+
const [activeModal, setActiveModal] = useState<"recieved" | "sent" | null>(
15+
null,
16+
);
17+
18+
// modal logic
19+
// const handleOpen = () => {
20+
// setIsModalOpen(true);
21+
// };
22+
// const handleClose = () => {
23+
// setIsModalOpen(false);
24+
// };
25+
726
return (
827
<>
928
{/* 1. Navigation Bar */}
@@ -72,17 +91,74 @@ const UserNavbar = () => {
7291
My Inventory
7392
</button>
7493
</Link>
75-
<Link href="/user_page">
76-
<button className="rounded bg-blue-200 px-4 py-2 hover:bg-blue-300">
77-
Profile
78-
</button>
79-
</Link>
94+
95+
{user ? (
96+
<div className="flex items-center gap-4">
97+
<div className="group relative">
98+
<Link href="/user_page">
99+
<button className="rounded bg-blue-200 px-4 py-2 hover:bg-blue-300">
100+
Hello, {user.username}
101+
</button>
102+
</Link>
103+
{/* Dropdown */}
104+
<div className="pointer-events-auto absolute left-0 top-full hidden w-56 rounded bg-white shadow-lg group-hover:block">
105+
<button
106+
className="rounded px-4 py-2 hover:bg-blue-100"
107+
onClick={() => {
108+
setActiveModal("recieved");
109+
setIsModalOpen(true);
110+
}}
111+
>
112+
Friend Requests Recieved
113+
</button>
114+
<button
115+
className="rounded px-4 py-2 hover:bg-blue-100"
116+
onClick={() => {
117+
setActiveModal("sent");
118+
setIsModalOpen(true);
119+
}}
120+
>
121+
Friend Requests Sent
122+
</button>
123+
</div>
124+
</div>
125+
<button
126+
onClick={logout}
127+
className="rounded bg-red-200 px-4 py-2 hover:bg-red-300"
128+
>
129+
Logout
130+
</button>
131+
</div>
132+
) : (
133+
<div>
134+
<Link href="/user_login">
135+
<button
136+
onClick={logout}
137+
className="rounded bg-blue-200 px-4 py-2 hover:bg-blue-300"
138+
>
139+
Login
140+
</button>
141+
{/* <a href="/user_login">Login</a> */}
142+
</Link>
143+
</div>
144+
)}
80145
</div>
146+
{activeModal === "recieved" && (
147+
<UserFriendsRecieved
148+
isOpen={isModalOpen}
149+
onClose={() => setIsModalOpen(false)}
150+
/>
151+
)}
152+
{activeModal === "sent" && (
153+
<UserFriendsSent
154+
isOpen={isModalOpen}
155+
onClose={() => setIsModalOpen(false)}
156+
/>
157+
)}
81158
</nav>
82159
</div>
83160
</>
84161
);
85162
};
86163

87-
// export to make the function available to other parts of the app
88164
export default UserNavbar;

0 commit comments

Comments
 (0)