build bug fixes

This commit is contained in:
makearmy 2025-09-29 19:39:37 -04:00
parent bf45c515db
commit fbe29a5cdc

View file

@ -13,24 +13,40 @@ export default async function Page() {
}
const DIRECTUS = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
const res = await fetch(
`${DIRECTUS}/items/user_rig_type?fields=id,name&sort=sort`,
{
headers: {
Authorization: `Bearer ${ma_at}`,
Accept: "application/json",
"Cache-Control": "no-store",
},
cache: "no-store",
let rigTypes: Opt[] = [];
try {
const res = await fetch(
`${DIRECTUS}/items/user_rig_type?fields=id,name&sort=sort`,
{
headers: {
Authorization: `Bearer ${ma_at}`,
Accept: "application/json",
"Cache-Control": "no-store",
},
cache: "no-store",
}
);
if (res.ok) {
const json = await res.json();
rigTypes = (json?.data ?? []).map((r: any) => ({
id: r.id,
label: r.name ?? String(r.id),
}));
} else {
// Optional: log server-side for debugging
// console.error("Failed to fetch user_rig_type", res.status);
rigTypes = [];
}
} catch {
rigTypes = [];
}
return (
<div className="rounded-lg border p-6">
<h2 className="mb-4 text-xl font-semibold">Rigs</h2>
<RigsSwitcher rigTypes={rigTypes} />
</div>
);
// Be resilient: if this fails, just show no options so the page still builds
const json = res.ok ? await res.json().catch(() => ({ data: [] })) : { data: [] };
const rigTypes: Opt[] = (json?.data ?? []).map((r: any) => ({
id: r.id,
label: r.name ?? String(r.id),
}));
return <RigsSwitcher rigTypes={rigTypes} />;
}