build bug fixes

This commit is contained in:
makearmy 2025-09-29 19:12:10 -04:00
parent 2c858929e4
commit bf45c515db
2 changed files with 40 additions and 30 deletions

View file

@ -1,30 +1,36 @@
// app/rigs/page.tsx // app/portal/rigs/page.tsx
import RigBuilderServer from "./RigBuilderServer"; import { cookies } from "next/headers";
import RigsListClient from "./RigsListClient"; import { redirect } from "next/navigation";
import RigsSwitcher from "@/components/portal/RigsSwitcher";
export default function Page() { type Opt = { id: string | number; label: string };
return (
<div className="p-4 space-y-6">
<header>
<h1 className="text-2xl font-bold mb-1">Rigs</h1>
<p className="text-sm text-muted-foreground">
Manage rigs used when submitting settings.
</p>
</header>
<div className="grid gap-6 md:grid-cols-2"> export default async function Page() {
{/* Left: existing rigs */} const jar = await cookies(); // Next 15: async
<section> const ma_at = jar.get("ma_at")?.value;
<h2 className="text-lg font-semibold mb-2">My Rigs</h2> if (!ma_at) {
<RigsListClient /> redirect("/auth/sign-in?next=/portal/rigs");
</section> }
{/* Right: create a new rig (server-provided rig types) */} const DIRECTUS = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
<section> const res = await fetch(
<h2 className="text-lg font-semibold mb-2">Create Rig</h2> `${DIRECTUS}/items/user_rig_type?fields=id,name&sort=sort`,
<RigBuilderServer /> {
</section> headers: {
</div> Authorization: `Bearer ${ma_at}`,
</div> Accept: "application/json",
"Cache-Control": "no-store",
},
cache: "no-store",
}
); );
// 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} />;
} }

View file

@ -6,12 +6,14 @@ import { cn } from "@/lib/utils";
import RigsListClient from "@/app/rigs/RigsListClient"; import RigsListClient from "@/app/rigs/RigsListClient";
import RigBuilderClient from "@/app/rigs/RigBuilderClient"; import RigBuilderClient from "@/app/rigs/RigBuilderClient";
type Opt = { id: string | number; label: string };
const TABS = [ const TABS = [
{ key: "my", label: "My Rigs" }, { key: "my", label: "My Rigs" },
{ key: "add", label: "Add Rig" }, { key: "add", label: "Add Rig" },
]; ];
function Panel({ tab }: { tab: string }) { function Panel({ tab, rigTypes }: { tab: string; rigTypes: Opt[] }) {
switch (tab) { switch (tab) {
case "my": case "my":
return ( return (
@ -22,7 +24,7 @@ function Panel({ tab }: { tab: string }) {
case "add": case "add":
return ( return (
<div className="rounded-md border p-4"> <div className="rounded-md border p-4">
<RigBuilderClient /> <RigBuilderClient rigTypes={rigTypes} />
</div> </div>
); );
default: default:
@ -30,7 +32,7 @@ function Panel({ tab }: { tab: string }) {
} }
} }
export default function RigsSwitcher() { export default function RigsSwitcher({ rigTypes }: { rigTypes: Opt[] }) {
const router = useRouter(); const router = useRouter();
const sp = useSearchParams(); const sp = useSearchParams();
const active = sp.get("t") || "my"; const active = sp.get("t") || "my";
@ -50,7 +52,9 @@ export default function RigsSwitcher() {
onClick={() => setTab(key)} onClick={() => setTab(key)}
className={cn( className={cn(
"rounded-md border px-3 py-1.5 text-sm transition", "rounded-md border px-3 py-1.5 text-sm transition",
active === key ? "bg-primary text-primary-foreground" : "hover:bg-muted" active === key
? "bg-primary text-primary-foreground"
: "hover:bg-muted"
)} )}
> >
{label} {label}
@ -58,7 +62,7 @@ export default function RigsSwitcher() {
))} ))}
</div> </div>
<Panel tab={active} /> <Panel tab={active} rigTypes={rigTypes} />
</div> </div>
); );
} }