diff --git a/FRONTEND/src/components/ui/FilterPanel.jsx b/FRONTEND/src/components/ui/FilterPanel.jsx index db5f8ad..f6b9bb1 100644 --- a/FRONTEND/src/components/ui/FilterPanel.jsx +++ b/FRONTEND/src/components/ui/FilterPanel.jsx @@ -7,7 +7,7 @@ import { } from '@chakra-ui/react'; import { useProductStore } from '../../store/product'; -const FilterPanel = ({ filters, setFilters }) => { +const FilterPanel = ({ filters, setFilters, isDisabled = false }) => { const [localFilters, setLocalFilters] = useState(filters); const [categories, setCategories] = useState([]); const [brands, setBrands] = useState([]); @@ -101,6 +101,7 @@ const FilterPanel = ({ filters, setFilters }) => { handleCategoryChange(cat)} > @@ -122,6 +123,7 @@ const FilterPanel = ({ filters, setFilters }) => { handleBrandChange(brand)} > @@ -143,6 +145,7 @@ const FilterPanel = ({ filters, setFilters }) => { @@ -166,6 +169,7 @@ const FilterPanel = ({ filters, setFilters }) => { onChange={(e) => setLocalFilters({ ...localFilters, minRating: Number(e.target.value) }) } + isDisabled={isDisabled} > @@ -184,6 +188,7 @@ const FilterPanel = ({ filters, setFilters }) => { onChange={(e) => setLocalFilters({ ...localFilters, inStock: e.target.checked }) } + isDisabled={isDisabled} > In Stock Only @@ -192,10 +197,11 @@ const FilterPanel = ({ filters, setFilters }) => { - - diff --git a/FRONTEND/src/pages/HomePage.jsx b/FRONTEND/src/pages/HomePage.jsx index 7b88409..2d4b448 100644 --- a/FRONTEND/src/pages/HomePage.jsx +++ b/FRONTEND/src/pages/HomePage.jsx @@ -157,6 +157,7 @@ const HomePage = () => { }} maxW="250px" aria-label="Sort products" + isDisabled={isSearching} > @@ -195,7 +196,7 @@ const HomePage = () => { - { {/* Sidebar with Filters — hidden when store has no products */} {!hasNoProducts && ( - + )} + {/* Product grid — skeletons while loading, real cards when ready */} diff --git a/FRONTEND/src/store/product.js b/FRONTEND/src/store/product.js index d5a57db..f3b69a8 100644 --- a/FRONTEND/src/store/product.js +++ b/FRONTEND/src/store/product.js @@ -140,8 +140,16 @@ export const useProductStore = create((set) =>({ try { const res = await fetch(`${API}/api/products/${pid}`, { method: "DELETE", - }); - const data = await res.json(); + }); + + if (!res.ok) { + set({ isDeleting: false }); + return { + success: false, + message: `Request failed with status ${res.status}`, + }; + } + const data = await res.json(); if (!data.success) { set({ isDeleting: false }); return { success: false, message: data.message }; @@ -178,9 +186,17 @@ export const useProductStore = create((set) =>({ const res = await fetch(`${API}/api/products/${pid}`, { method: "PUT", - body: formData, + body: formData, }); + if (!res.ok) { + set({ isSubmitting: false }); + return { + success: false, + message: `Request failed with status ${res.status}`, + }; + } + const data = await res.json(); if (!data.success) { set({ isSubmitting: false });