get product request fixed from catalog_selection bug

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-03-08 12:41:11 +05:00
parent 06ac90c391
commit aba11a939a

View File

@@ -21,14 +21,10 @@ export default function MainProduct() {
const getFiltersByType = useFilter((s) => s.getFiltersByType); const getFiltersByType = useFilter((s) => s.getFiltersByType);
const setProduct = useProductPageInfo((s) => s.setProducts); const setProduct = useProductPageInfo((s) => s.setProducts);
// ✅ FIX 1: parentID must be read here so the component re-renders when it changes
const parentID = useCatalog((state) => state.parentID); const parentID = useCatalog((state) => state.parentID);
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
// ✅ FIX 3: Reset page to 1 whenever parentID changes
// parentID changing means the user picked a new catalog section —
// staying on page 3 of the old section makes no sense.
useEffect(() => { useEffect(() => {
setCurrentPage(1); setCurrentPage(1);
}, [parentID]); }, [parentID]);
@@ -45,9 +41,6 @@ export default function MainProduct() {
}, [filter]); }, [filter]);
// ── Request URL ────────────────────────────────────────────────────────── // ── Request URL ──────────────────────────────────────────────────────────
// ✅ FIX 2: parentID added to deps array
// Without this, the memo never recomputed when parentID changed —
// the component would fetch the same old URL every time.
const requestLink = useMemo(() => { const requestLink = useMemo(() => {
const baseLink = category.have_sub_category const baseLink = category.have_sub_category
? endPoints.product.bySubCategory({ id: subCategory.id, currentPage }) ? endPoints.product.bySubCategory({ id: subCategory.id, currentPage })
@@ -61,7 +54,7 @@ export default function MainProduct() {
category.have_sub_category, category.have_sub_category,
subCategory.id, subCategory.id,
currentPage, currentPage,
parentID, // ✅ was missing parentID,
queryParams, queryParams,
]); ]);
@@ -72,7 +65,7 @@ export default function MainProduct() {
category.id, category.id,
category.have_sub_category, category.have_sub_category,
subCategory.id, subCategory.id,
parentID, // ✅ FIX 1: was missing — cache was never invalidated on parentID change parentID,
queryParams, queryParams,
currentPage, currentPage,
], ],
@@ -86,8 +79,6 @@ export default function MainProduct() {
const results = data?.results ?? []; const results = data?.results ?? [];
const totalPages = data?.totalPages ?? 1; const totalPages = data?.totalPages ?? 1;
// ↑ Removed useMemo — data is already memoized by React Query's select.
// Wrapping it again in useMemo adds overhead with zero benefit.
// ── Render states ──────────────────────────────────────────────────────── // ── Render states ────────────────────────────────────────────────────────
if (isLoading && !data) { if (isLoading && !data) {