|
2 | 2 | //import ""; |
3 | 3 |
|
4 | 4 | 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"; |
5 | 10 |
|
6 | 11 | 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 | + |
7 | 26 | return ( |
8 | 27 | <> |
9 | 28 | {/* 1. Navigation Bar */} |
@@ -72,17 +91,74 @@ const UserNavbar = () => { |
72 | 91 | My Inventory |
73 | 92 | </button> |
74 | 93 | </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 | + )} |
80 | 145 | </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 | + )} |
81 | 158 | </nav> |
82 | 159 | </div> |
83 | 160 | </> |
84 | 161 | ); |
85 | 162 | }; |
86 | 163 |
|
87 | | -// export to make the function available to other parts of the app |
88 | 164 | export default UserNavbar; |
0 commit comments