fixed part role mapping to categories. set a const for categories

This commit is contained in:
2025-12-02 21:13:17 -05:00
parent c51ce862a9
commit 4b823f49cf
196 changed files with 2820 additions and 164 deletions
+4 -14
View File
@@ -4,6 +4,7 @@ import { useEffect, useMemo, useState } from "react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
import { CATEGORIES } from "@/data/gunbuilderParts";
import { CATEGORY_TO_PART_ROLES } from "@/data/partRoleMappings";
import type { CategoryId, Part } from "@/types/gunbuilder";
type ViewMode = "card" | "list";
@@ -22,18 +23,6 @@ type GunbuilderProductFromApi = {
const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
const CATEGORY_TO_PART_ROLES: Record<CategoryId, string[]> = {
upper: ["upper-receiver"],
barrel: ["barrel"],
handguard: ["handguard"],
chargingHandle: ["charging-handle"],
buffer: ["buffer-kit"],
lowerParts: ["lower-parts-kit"],
sights: ["sight"],
lower: ["lower-receiver"],
optic: ["optic"],
stock: ["stock"],
};
// sort options
type SortOption = "relevance" | "price-asc" | "price-desc" | "brand-asc";
@@ -80,10 +69,11 @@ export default function CategoryPage() {
async function fetchCategoryParts() {
try {
setLoading(true);
setLoading(true);
setError(null);
const roles = CATEGORY_TO_PART_ROLES[categoryId] ?? [];
// FIX: determine which backend partRoles map to this category
const roles = CATEGORY_TO_PART_ROLES[categoryId] ?? [];
const search = new URLSearchParams();
search.set("platform", "AR-15");