From 68745f087dc10f47929ad05ac0f5529479fb078c Mon Sep 17 00:00:00 2001 From: ashk6645 Date: Thu, 25 Sep 2025 23:36:42 +0530 Subject: [PATCH 1/2] Minor fixes --- components/ErrorBoundary.jsx | 0 components/Navbar.jsx | 129 +++++++++++++++++------------ components/ProductCardSkeleton.jsx | 0 components/ui/Button.jsx | 0 components/ui/Input.jsx | 0 hooks/useCart.js | 0 hooks/useIntersectionObserver.js | 0 lib/utils.js | 0 8 files changed, 75 insertions(+), 54 deletions(-) create mode 100644 components/ErrorBoundary.jsx create mode 100644 components/ProductCardSkeleton.jsx create mode 100644 components/ui/Button.jsx create mode 100644 components/ui/Input.jsx create mode 100644 hooks/useCart.js create mode 100644 hooks/useIntersectionObserver.js create mode 100644 lib/utils.js diff --git a/components/ErrorBoundary.jsx b/components/ErrorBoundary.jsx new file mode 100644 index 00000000..e69de29b diff --git a/components/Navbar.jsx b/components/Navbar.jsx index d7fb5c82..4463b80b 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -2,68 +2,89 @@ import { Search, ShoppingCart } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; -import { useState } from "react"; +import { useState, useCallback } from "react"; import { useSelector } from "react-redux"; const Navbar = () => { + const router = useRouter(); + const [search, setSearch] = useState(""); + const cartCount = useSelector((state: any) => state.cart.total); - const router = useRouter(); + const handleSearch = useCallback( + (e: React.FormEvent) => { + e.preventDefault(); + if (search.trim()) { + router.push(`/shop?search=${encodeURIComponent(search.trim())}`); + } + }, + [router, search] + ); - const [search, setSearch] = useState('') - const cartCount = useSelector(state => state.cart.total) + return ( + - ) -} - -export default Navbar \ No newline at end of file +export default Navbar; diff --git a/components/ProductCardSkeleton.jsx b/components/ProductCardSkeleton.jsx new file mode 100644 index 00000000..e69de29b diff --git a/components/ui/Button.jsx b/components/ui/Button.jsx new file mode 100644 index 00000000..e69de29b diff --git a/components/ui/Input.jsx b/components/ui/Input.jsx new file mode 100644 index 00000000..e69de29b diff --git a/hooks/useCart.js b/hooks/useCart.js new file mode 100644 index 00000000..e69de29b diff --git a/hooks/useIntersectionObserver.js b/hooks/useIntersectionObserver.js new file mode 100644 index 00000000..e69de29b diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..e69de29b From 486cfb762d89bfe8e37592f9b1065ae66ba748d3 Mon Sep 17 00:00:00 2001 From: ashk6645 Date: Thu, 25 Sep 2025 23:45:08 +0530 Subject: [PATCH 2/2] Minor UI changes --- components/Navbar.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Navbar.jsx b/components/Navbar.jsx index 4463b80b..4fa81296 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -8,10 +8,10 @@ import { useSelector } from "react-redux"; const Navbar = () => { const router = useRouter(); const [search, setSearch] = useState(""); - const cartCount = useSelector((state: any) => state.cart.total); + const cartCount = useSelector((state) => state.cart.total); const handleSearch = useCallback( - (e: React.FormEvent) => { + (e) => { e.preventDefault(); if (search.trim()) { router.push(`/shop?search=${encodeURIComponent(search.trim())}`);