From 78a7ff2060fb41f9ae908431a268c192d917dee2 Mon Sep 17 00:00:00 2001 From: makearmy Date: Sat, 27 Sep 2025 18:30:18 -0400 Subject: [PATCH] portal pages update for details view --- app/portal/laser-settings/page.tsx | 83 +++++++++++++++++++----------- app/portal/laser-sources/page.tsx | 44 +++++++++++++--- app/portal/materials/page.tsx | 62 ++++++++++++++++++++-- app/portal/projects/page.tsx | 43 ++++++++++++++-- middleware.ts | 8 +-- 5 files changed, 193 insertions(+), 47 deletions(-) diff --git a/app/portal/laser-settings/page.tsx b/app/portal/laser-settings/page.tsx index 2a88d8c8..ec7e589b 100644 --- a/app/portal/laser-settings/page.tsx +++ b/app/portal/laser-settings/page.tsx @@ -1,40 +1,65 @@ -// app/portal/laser-settings/page.tsx -import { redirect } from "next/navigation"; -import SettingsSwitcher from "@/components/portal/SettingsSwitcher"; +"use client"; + +import dynamic from "next/dynamic"; +import { useSearchParams, useRouter } from "next/navigation"; + +// Your existing list/tabs component for the four settings lists: +const SettingsSwitcher = dynamic(() => import("@/components/portal/SettingsSwitcher"), { ssr: false }); export const metadata = { title: "MakerDash • Laser Settings" }; -function pickOne(v: T | T[] | undefined): T | undefined { - if (Array.isArray(v)) return v[0]; - return v; -} +export default function LaserSettingsPortalPage() { + const search = useSearchParams(); + const router = useRouter(); + const t = (search.get("t") || "fiber").toLowerCase(); // fiber | uv | co2-galvo | co2-gantry + const id = search.get("id"); -export default function LaserSettingsPortalPage({ - searchParams, -}: { - searchParams?: Record; -}) { - // Read tab + optional id from query - const t = (pickOne(searchParams?.t) || "fiber").toLowerCase(); - const id = pickOne(searchParams?.id); + // Build canonical detail route we already have in /app/settings/*/[id]/ + const embedSrc = id + ? t === "fiber" + ? `/settings/fiber/${encodeURIComponent(id)}` + : t === "uv" + ? `/settings/uv/${encodeURIComponent(id)}` + : t === "co2-galvo" + ? `/settings/co2-galvo/${encodeURIComponent(id)}` + : t === "co2-gantry" + ? `/settings/co2-gantry/${encodeURIComponent(id)}` + : null + : null; - // If an id is present, hop directly to the existing detail route - if (id) { - const slugMap: Record = { - fiber: "fiber", - uv: "uv", - "co2-galvo": "co2-galvo", - "co2-gantry": "co2-gantry", - }; - const slug = slugMap[t] ?? "fiber"; - redirect(`/settings/${slug}/${encodeURIComponent(id)}`); - } + const goList = () => router.replace(`/portal/laser-settings?t=${encodeURIComponent(t)}`); - // Otherwise show the normal portal view return (
-

Laser Settings

- +
+

Laser Settings

+
+ + +
+
+ + {/* List view (existing) */} + {!id && } + + {/* Detail view (embed canonical page) */} + {id && embedSrc && ( +