fixed part role calls and some other stuff

This commit is contained in:
2025-12-13 10:07:11 -05:00
parent 978b9df96c
commit 0f10ff4e09
4 changed files with 74 additions and 61 deletions
+18 -6
View File
@@ -155,7 +155,9 @@ export default function GunbuilderPage() {
const [scopedRes, universalRes] = await Promise.all([
fetch(scopedUrl, { signal: controller.signal }),
fetch(universalUrl, { signal: controller.signal }).catch(() => null as any),
fetch(universalUrl, { signal: controller.signal }).catch(
() => null as any
),
]);
if (!scopedRes || !scopedRes.ok) {
@@ -174,12 +176,20 @@ export default function GunbuilderPage() {
const normalize = (data: GunbuilderProductFromApi[]): Part[] =>
data
.map((p): Part | null => {
const categoryId = PART_ROLE_TO_CATEGORY[p.partRole];
const normalizedRole = (p.partRole ?? "")
.trim()
.toLowerCase()
.replace(/_/g, "-");
const categoryId = PART_ROLE_TO_CATEGORY[normalizedRole];
if (!categoryId) return null;
// Only keep truly-universal categories from the universal feed
// so we don't accidentally mix platforms for platform-scoped parts.
if (data === universalData && !UNIVERSAL_CATEGORIES.has(categoryId)) {
if (
data === universalData &&
!UNIVERSAL_CATEGORIES.has(categoryId)
) {
return null;
}
@@ -471,13 +481,15 @@ export default function GunbuilderPage() {
onChange={(e) => {
const next = e.target.value as (typeof PLATFORMS)[number];
setPlatform(next);
// Keep URL in sync so navigation + refresh preserve platform
const qp = new URLSearchParams(searchParams.toString());
qp.set("platform", next);
qp.delete("select");
router.replace(`/builder?${qp.toString()}`, { scroll: false });
router.replace(`/builder?${qp.toString()}`, {
scroll: false,
});
}}
className="rounded-md border border-zinc-700 bg-zinc-900 px-2 py-1 text-xs text-zinc-100 focus:outline-none focus:ring-1 focus:ring-amber-400"
>