Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 44 additions & 30 deletions src/components/Navbar/UserNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,12 @@ import { FaUserCircle } from "react-icons/fa";
const Navbar = ({ isAdmin }) => {
const [isOpen, setIsOpen] = useState(false);
const [searchTerm, setSearchTerm] = useState("");
// const [username, setUsername] = useState("");
const username = localStorage.getItem("username");
const [showDropdown, setShowDropdown] = useState(false);
const navigate = useNavigate();
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
const dropdownRef = useRef(null);

// useEffect(() => {
// const fetchUsername = async () => {
// try {
// const username = localStorage.getItem("username");
// console.log(username);
// } catch (error) {
// console.error("Error fetching username:", error);
// setUsername("User");
// }
// };

// if (isLoggedIn) {
// fetchUsername();
// }
// }, [isLoggedIn]);

const toggleNavbar = () => setIsOpen(!isOpen);
const handleSearch = (e) => setSearchTerm(e.target.value);

Expand Down Expand Up @@ -74,27 +57,32 @@ const Navbar = ({ isAdmin }) => {
<div className="py-1 flex justify-evenly items-center">
<Link
to="/popularCategories/fashionAccessories"
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 font-bold text-base">
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 font-bold text-base"
>
Fashion
</Link>
<Link
to="/popularCategories/customizedGifts"
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold">
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold"
>
Gifts
</Link>
<Link
to="/popularCategories/furnitureDecor"
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold">
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold"
>
Furniture
</Link>
<Link
to="/popularCategories/printingStationery"
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold">
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold"
>
Stationery
</Link>
<Link
to="/popularCategories/bodyCare"
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold">
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold"
>
Body-Care
</Link>
</div>
Expand All @@ -110,10 +98,9 @@ const Navbar = ({ isAdmin }) => {
handleSearch={handleSearch}
/>
<CartIcon />
<DarkModeToggle /> {/* Add DarkModeToggle here */}
{isLoggedIn ? (
<div className="relative flex gap-3 items-center">
{/* need styling fix then implement only */}
{/* <p className="mr-2 overflow-hidden flex text-gray-800">{`Hi, ${username}`}</p> */}
<FaUserCircle
onClick={handleDropdownToggle}
className="text-3xl cursor-pointer"
Expand All @@ -122,15 +109,18 @@ const Navbar = ({ isAdmin }) => {
{showDropdown && (
<div
ref={dropdownRef}
className="absolute right-0 mt-32 w-48 bg-white rounded-md shadow-lg py-1">
className="absolute right-0 mt-32 w-48 bg-white rounded-md shadow-lg py-1"
>
<Link
to="/dashboard"
className="block px-4 py-2 text-gray-800 hover:bg-gray-200">
className="block px-4 py-2 text-gray-800 hover:bg-gray-200"
>
Dashboard
</Link>
<button
onClick={handleLogout}
className="block px-4 py-2 text-gray-800 hover:bg-gray-200 w-full text-left">
className="block px-4 py-2 text-gray-800 hover:bg-gray-200 w-full text-left"
>
Logout
</button>
</div>
Expand All @@ -144,13 +134,15 @@ const Navbar = ({ isAdmin }) => {
<div className="-mr-2 flex md:hidden">
<button
onClick={toggleNavbar}
className="inline-flex items-center justify-center p-2 rounded-md text-green-800 hover:text-gray-600 focus:outline-none">
className="inline-flex items-center justify-center p-2 rounded-md text-green-800 hover:text-gray-600 focus:outline-none"
>
{isOpen ? (
<svg
className="h-6 w-6"
stroke="#15803D"
fill="#15803D"
viewBox="0 0 24 24">
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
Expand All @@ -163,7 +155,8 @@ const Navbar = ({ isAdmin }) => {
className="h-6 w-6"
stroke="#15803D"
fill="#15803D"
viewBox="0 0 24 24">
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
Expand Down Expand Up @@ -192,4 +185,25 @@ const Navbar = ({ isAdmin }) => {
);
};

const DarkModeToggle = () => {
const [isDarkMode, setIsDarkMode] = useState(false);

useEffect(() => {
if (isDarkMode) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}, [isDarkMode]);

return (
<button
onClick={() => setIsDarkMode(!isDarkMode)}
className="p-2 rounded-full hover:bg-gray-200"
>
{isDarkMode ? "🌙" : "☀️"}
</button>
);
};

export default Navbar;