From 7166ff2cb72f7bb88f69f58f3f17fc18e6d72aed Mon Sep 17 00:00:00 2001 From: Tejas Panchal Date: Sun, 27 Jul 2025 14:42:05 +0530 Subject: [PATCH] fixed navbar --- src/components/navbar/Navbar.jsx | 66 +++++++----- src/components/searchbar/MobileSearch.jsx | 117 +++++++++++++--------- src/components/suggestion/Suggestion.jsx | 49 +++++---- 3 files changed, 136 insertions(+), 96 deletions(-) diff --git a/src/components/navbar/Navbar.jsx b/src/components/navbar/Navbar.jsx index 6cbe397..d8ee8d9 100644 --- a/src/components/navbar/Navbar.jsx +++ b/src/components/navbar/Navbar.jsx @@ -3,6 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faBars, faRandom, + faMagnifyingGlass, } from "@fortawesome/free-solid-svg-icons"; import { useLanguage } from "@/src/context/LanguageContext"; import { Link, useLocation } from "react-router-dom"; @@ -19,6 +20,7 @@ function Navbar() { ); const [isScrolled, setIsScrolled] = useState(false); const [isSidebarOpen, setIsSidebarOpen] = useState(false); + const [isMobileSearchOpen, setIsMobileSearchOpen] = useState(false); useEffect(() => { const handleScroll = () => { @@ -53,9 +55,8 @@ function Navbar() { return ( - ); } diff --git a/src/components/searchbar/MobileSearch.jsx b/src/components/searchbar/MobileSearch.jsx index fc2acbd..4843b49 100644 --- a/src/components/searchbar/MobileSearch.jsx +++ b/src/components/searchbar/MobileSearch.jsx @@ -1,11 +1,12 @@ import Suggestion from '../suggestion/Suggestion'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons'; +import { faMagnifyingGlass, faRandom } from '@fortawesome/free-solid-svg-icons'; import useSearch from '@/src/hooks/useSearch'; -import { useNavigate } from 'react-router-dom'; +import { Link, useNavigate, useLocation } from 'react-router-dom'; -function MobileSearch() { +function MobileSearch({ onClose }) { const navigate = useNavigate(); + const location = useLocation(); const { isSearchVisible, searchValue, @@ -16,60 +17,80 @@ function MobileSearch() { suggestionRefs, addSuggestionRef, } = useSearch(); + const handleSearchClick = () => { - if (searchValue.trim() && window.innerWidth <= 600) { + if (searchValue.trim()) { navigate(`/search?keyword=${encodeURIComponent(searchValue)}`); + onClose?.(); } }; + + const handleRandomClick = () => { + if (location.pathname === "/random") { + window.location.reload(); + } + onClose?.(); + }; + return ( - <> - {isSearchVisible && ( -
-
- setSearchValue(e.target.value)} - onFocus={() => setIsFocused(true)} - onBlur={() => { - setTimeout(() => { - const isInsideSuggestionBox = suggestionRefs.current.some( - (ref) => ref && ref.contains(document.activeElement), - ); - if (!isInsideSuggestionBox) { - setIsFocused(false); - } - }, 100); - }} - onKeyDown={(e) => { - if (e.key === 'Enter') { - handleSearchClick(); +
+
+
+ setSearchValue(e.target.value)} + onFocus={() => setIsFocused(true)} + onBlur={() => { + setTimeout(() => { + const isInsideSuggestionBox = suggestionRefs.current.some( + (ref) => ref && ref.contains(document.activeElement), + ); + if (!isInsideSuggestionBox) { + setIsFocused(false); } - }} + }, 100); + }} + onKeyDown={(e) => { + if (e.key === 'Enter') { + handleSearchClick(); + } + }} + /> + -
- {searchValue.trim() && isFocused && ( -
- -
- )} + +
+ + + +
+ {searchValue.trim() && isFocused && ( +
+
)} - +
); } diff --git a/src/components/suggestion/Suggestion.jsx b/src/components/suggestion/Suggestion.jsx index 5a1267b..c1f93d0 100644 --- a/src/components/suggestion/Suggestion.jsx +++ b/src/components/suggestion/Suggestion.jsx @@ -4,7 +4,7 @@ import BouncingLoader from "../ui/bouncingloader/Bouncingloader"; import { FaChevronRight } from "react-icons/fa"; import { Link } from "react-router-dom"; -function Suggestion({ keyword, className }) { +function Suggestion({ keyword, className, onSuggestionClick }) { const [suggestion, setSuggestion] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -31,32 +31,36 @@ function Suggestion({ keyword, className }) { return (
{loading ? ( ) : error && !suggestion ? ( -
Error loading suggestions
+
Error loading suggestions
) : suggestion && hasFetched ? ( -
+
{suggestion.map((item, index) => ( { e.target.src = "https://i.postimg.cc/HnHKvHpz/no-avatar.jpg"; @@ -64,26 +68,26 @@ function Suggestion({ keyword, className }) { />
{item?.title && ( -

+

{item.title || "N/A"}

)} {item?.japanese_title && ( -

+

{item.japanese_title || "N/A"}

)} {(item?.releaseDate || item?.showType || item?.duration) && ( -
-

+

+

{item.releaseDate || "N/A"}

- -

+ +

{item.showType || "N/A"}

- -

+ +

{item.duration || "N/A"}

@@ -93,20 +97,21 @@ function Suggestion({ keyword, className }) { ))} {!loading && hasFetched && (
-

+

View all results

- +
)}
) : hasFetched ? ( -

No results found!

+

No results found!

) : null}
);