no longer price sort of frontend

This commit is contained in:
2026-01-02 09:56:51 -05:00
parent 228d08337f
commit b7e3db8d34
2 changed files with 49 additions and 25 deletions
+26 -4
View File
@@ -158,19 +158,34 @@ export default function PartsBrowseClient(props: {
// optional server search + sort (backend can ignore for now)
if (searchQuery.trim()) search.set("q", searchQuery.trim());
if (brandFilter.length) brandFilter.forEach((b) => search.append("brand", b));
if (brandFilter.length)
brandFilter.forEach((b) => search.append("brand", b));
// sort mapping
// sort mapping (Spring-style: sort=field,dir)
switch (sortBy) {
case "price-asc":
search.set("sort", "price,asc");
break;
case "price-desc":
search.set("sort", "price,desc");
break;
case "brand-asc":
search.set("sort", "brand,asc");
break;
case "relevance":
default:
// fallback (or whatever you consider "relevance")
search.set("sort", "updatedAt,desc");
break;
}
const res = await fetch(`${API_BASE_URL}/api/v1/catalog/options?${search.toString()}`, {
const res = await fetch(
`${API_BASE_URL}/api/v1/catalog/options?${search.toString()}`,
{
signal: controller.signal,
});
}
);
if (!res.ok) throw new Error(`Failed to load products (${res.status})`);
@@ -209,7 +224,14 @@ export default function PartsBrowseClient(props: {
fetchParts();
return () => controller.abort();
}, [partRole, effectivePlatform, currentPage, searchQuery, sortBy, brandFilter]);
}, [
partRole,
effectivePlatform,
currentPage,
searchQuery,
sortBy,
brandFilter,
]);
// Reset pagination on filters
useEffect(() => {
setCurrentPage(1);
+7 -5
View File
@@ -47,21 +47,23 @@ export function slugify(input: string) {
export async function fetchProducts(params: {
platform: string;
partRole: string;
sort?: string; // ex: "price,asc"
}) {
const { platform, partRole } = params;
const { platform, partRole, sort } = params;
const url =
`${API_BASE_URL}/api/v1/products?` +
new URLSearchParams({
const sp = new URLSearchParams({
platform,
partRoles: partRole,
});
if (sort) sp.set("sort", sort);
const url = `${API_BASE_URL}/api/v1/products?${sp.toString()}`;
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) throw new Error(`Failed to load products (${res.status})`);
const data = (await res.json()) as ProductListItem[];
// Ensure each item has a "productSlug" of the form "{id}-{slugified-name}"
return data.map((p) => ({
...p,
productSlug: `${p.id}-${slugify(p.name)}`,