no longer price sort of frontend
This commit is contained in:
+10
-8
@@ -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)}`,
|
||||
|
||||
Reference in New Issue
Block a user