Description
In frontend/shop.html and frontend/scripts/shop.js, selecting category filters, price range sliders, or sorting orders updates the UI dynamically but does not update window.location.search. When users refresh the page, click the browser back button, or copy the URL to share with others, all active filters reset to default.
Steps to Reproduce
- Open
frontend/shop.html.
- Filter by Category: "T-Shirts", Price: "$20 - $50", and Sort: "Price: Low to High".
- Check the browser URL address bar; it remains
/shop.html without query params.
- Refresh the page; all filters are cleared and all products are displayed.
Expected Behavior
- Frontend: Whenever filter or sort state changes in
shop-controls.js, update URL params via history.pushState or history.replaceState (e.g. shop.html?category=tshirts&minPrice=20&maxPrice=50&sort=price_asc).
- Frontend: On
window.DOMContentLoaded and window.onpopstate, parse URL params and pre-populate filter controls before fetching products.
Implementation Hints
Frontend (frontend/scripts/shop-filter-utils.js & frontend/scripts/shop.js):
export function syncFiltersToUrl(filters) {
const params = new URLSearchParams();
if (filters.category) params.set("category", filters.category);
if (filters.minPrice) params.set("minPrice", filters.minPrice);
if (filters.maxPrice) params.set("maxPrice", filters.maxPrice);
if (filters.sort) params.set("sort", filters.sort);
const newUrl = `${window.location.pathname}?${params.toString()}`;
window.history.replaceState({}, "", newUrl);
}
export function loadFiltersFromUrl() {
const params = new URLSearchParams(window.location.search);
return {
category: params.get("category") || "",
minPrice: params.get("minPrice") || "",
maxPrice: params.get("maxPrice") || "",
sort: params.get("sort") || "default"
};
}
Affected Files
- frontend/scripts/shop.js
- frontend/scripts/shop-controls.js
- frontend/scripts/shop-filter-utils.js
- frontend/shop.html
Labels
type:feature, level:beginner, GSSoC-26
Description
In
frontend/shop.htmlandfrontend/scripts/shop.js, selecting category filters, price range sliders, or sorting orders updates the UI dynamically but does not updatewindow.location.search. When users refresh the page, click the browser back button, or copy the URL to share with others, all active filters reset to default.Steps to Reproduce
frontend/shop.html./shop.htmlwithout query params.Expected Behavior
shop-controls.js, update URL params viahistory.pushStateorhistory.replaceState(e.g.shop.html?category=tshirts&minPrice=20&maxPrice=50&sort=price_asc).window.DOMContentLoadedandwindow.onpopstate, parse URL params and pre-populate filter controls before fetching products.Implementation Hints
Frontend (
frontend/scripts/shop-filter-utils.js&frontend/scripts/shop.js):Affected Files
Labels
type:feature, level:beginner, GSSoC-26