-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress bar overlaps navbar fixed #1881
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ede5e1
fixed progress bar overlap in navbar
Priyal208 38e29b7
Merge branch 'codervivek5:main' into nav
Priyal208 e608b02
Rename UserNavbar .jsx to UserNavbar.jsx
Priyal208 f22f6bb
Merge branch 'main' into nav
Priyal208 b1f775d
Merge branch 'main' into nav
Priyal208 3dbb707
Merge branch 'main' into nav
Priyal208 aa00166
Merge branch 'codervivek5:main' into nav
Priyal208 c699577
Merge branch 'main' into nav
Priyal208 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import React, { useState, useRef, useEffect } from "react"; | ||
import { useNavigate, Link } from "react-router-dom"; | ||
import NavLogo from "./NavLogo"; | ||
import SearchBar from "../SearchBar/SearchBar"; | ||
import CartIcon from "./CartIcon"; | ||
import AuthButton from "./AuthButton"; | ||
import MobileMenu from "./MobileMenu"; | ||
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); | ||
|
||
const handleLogout = () => { | ||
const confirmed = window.confirm("Are you sure you want to logout?"); | ||
if (confirmed) { | ||
localStorage.setItem("isLoggedIn", false); | ||
localStorage.removeItem("username"); | ||
alert("Logout Successful."); | ||
navigate("/login"); | ||
} | ||
}; | ||
|
||
const handleDropdownToggle = () => { | ||
setShowDropdown((prev) => !prev); | ||
}; | ||
|
||
const handleClickOutside = (e) => { | ||
if (dropdownRef.current && !dropdownRef.current.contains(e.target)) { | ||
setShowDropdown(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener("mousedown", handleClickOutside); | ||
return () => { | ||
document.removeEventListener("mousedown", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<nav className="bg-[#ecd5c5] shadow-lg md:w-full fixed md:z-50 -mt-1 w-[100vw] z-50 pt-4 sm:pt-5"> | ||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | ||
<div className="flex justify-between h-20"> | ||
<div className="flex items-center w-full"> | ||
<NavLogo /> | ||
<div className="hidden md:block lg:block"> | ||
<div className="ml-10 flex items-baseline space-x-4"> | ||
<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"> | ||
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"> | ||
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"> | ||
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"> | ||
Stationary | ||
</Link> | ||
<Link | ||
to="/popularCategories/bodyCare" | ||
className="text-green-800 hover:text-green-500 hover:underline block px-4 py-2 text-base font-bold"> | ||
Body-Care | ||
</Link> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="flex items-center"> | ||
<div className="md:block hidden"> | ||
<div className="ml-4 flex items-center md:ml-6 gap-6"> | ||
<SearchBar | ||
searchTerm={searchTerm} | ||
handleSearch={handleSearch} | ||
/> | ||
<CartIcon /> | ||
{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" | ||
/> | ||
<span className="text-green-700 font-bold">{username}</span> | ||
{showDropdown && ( | ||
<div | ||
ref={dropdownRef} | ||
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"> | ||
Dashboard | ||
</Link> | ||
<button | ||
onClick={handleLogout} | ||
className="block px-4 py-2 text-gray-800 hover:bg-gray-200 w-full text-left"> | ||
Logout | ||
</button> | ||
</div> | ||
)} | ||
</div> | ||
) : ( | ||
<AuthButton isLoggedIn={isLoggedIn} /> | ||
)} | ||
</div> | ||
</div> | ||
<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"> | ||
{isOpen ? ( | ||
<svg | ||
className="h-6 w-6" | ||
stroke="#15803D" | ||
fill="#15803D" | ||
viewBox="0 0 24 24"> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
d="M6 18L18 6M6 6l12 12" | ||
/> | ||
</svg> | ||
) : ( | ||
<svg | ||
className="h-6 w-6" | ||
stroke="#15803D" | ||
fill="#15803D" | ||
viewBox="0 0 24 24"> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
d="M4 6h16M4 12h16M4 18h16" | ||
/> | ||
</svg> | ||
)} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<MobileMenu | ||
isOpen={isOpen} | ||
searchTerm={searchTerm} | ||
handleSearch={handleSearch} | ||
handleDropdown={handleDropdownToggle} | ||
openDropdown={showDropdown} | ||
isLoggedIn={isLoggedIn} | ||
handleLogout={handleLogout} | ||
username={username} | ||
/> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default Navbar; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve class names for readability.
The class names for styling can be improved for readability and maintainability.
Committable suggestion