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
+10 -8
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({
platform,
partRoles: partRole,
});
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)}`,