From f32afc642178c0b2851022056ee6cf9d3fb1de62 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Mon, 26 Oct 2026 22:20:54 -0400 Subject: [PATCH] feat(logistics): restyle vehicle catalog cards in tactical dossier style VehicleCard gains classification strip, corner brackets, squared corners, darkened cover imagery, faint grid texture and a permanent readout footer (matching CampaignCard). Fixes pre-existing defects: description rendered twice, category colors disagreed with the detail page, and stat accessors read nonexistent nested fields hidden by an 'as any' cast (now typed against Vehicle). Category color/label maps unified into src/lib/vehicles/categories.ts shared by card and detail pages. --- .../logistics/vehicles/VehiclesList.tsx | 4 +- .../logistics/vehicles/[id]/page.tsx | 15 +- .../frontend/logistics/VehicleCard.tsx | 260 +++++++++--------- src/lib/vehicles/categories.ts | 33 +++ 4 files changed, 170 insertions(+), 142 deletions(-) create mode 100644 src/lib/vehicles/categories.ts diff --git a/src/app/(frontend)/logistics/vehicles/VehiclesList.tsx b/src/app/(frontend)/logistics/vehicles/VehiclesList.tsx index 32676446..02f26c5d 100644 --- a/src/app/(frontend)/logistics/vehicles/VehiclesList.tsx +++ b/src/app/(frontend)/logistics/vehicles/VehiclesList.tsx @@ -29,9 +29,9 @@ export function VehiclesList({ vehicles }: { vehicles: Vehicle[] }) { <> {filtered.length > 0 ? ( -
+
{filtered.map((vehicle) => ( - + ))}
) : ( diff --git a/src/app/(frontend)/logistics/vehicles/[id]/page.tsx b/src/app/(frontend)/logistics/vehicles/[id]/page.tsx index 01955d93..91cafc83 100644 --- a/src/app/(frontend)/logistics/vehicles/[id]/page.tsx +++ b/src/app/(frontend)/logistics/vehicles/[id]/page.tsx @@ -5,6 +5,7 @@ import Link from "next/link"; import type { Resource, Structure, Technology } from "@/payload-types"; import { RichText } from "@payloadcms/richtext-lexical/react"; import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext"; +import { categoryLabel, categoryPillClasses } from "@/lib/vehicles/categories"; import { ArrowLeftIcon, BoxIcon, @@ -29,16 +30,6 @@ interface VehicleDetailPageProps { params: Promise<{ id: string }>; } -const categoryColors: Record = { - civilian: "bg-muted text-muted-foreground", - utility: "bg-blue-500/20 text-blue-400", - transport: "bg-green-500/20 text-green-400", - drone: "bg-violet-500/20 text-violet-400", - weaponized: "bg-red-500/20 text-red-400", - static: "bg-slate-500/20 text-slate-400", - military: "bg-amber-500/20 text-amber-400", -}; - const armorColors: Record = { none: "bg-muted text-muted-foreground", light: "bg-green-500/20 text-green-400", @@ -106,9 +97,9 @@ export default async function VehicleDetailPage({ params }: VehicleDetailPagePro {(vehicle.category ?? []).map((cat) => ( - {cat} + {categoryLabel(cat)} ))}
diff --git a/src/components/frontend/logistics/VehicleCard.tsx b/src/components/frontend/logistics/VehicleCard.tsx index 81ea87d0..27070a85 100644 --- a/src/components/frontend/logistics/VehicleCard.tsx +++ b/src/components/frontend/logistics/VehicleCard.tsx @@ -1,155 +1,159 @@ "use client"; import Link from "next/link"; -import { - Item, - ItemContent, - ItemDescription, - ItemHeader, - ItemMedia, - ItemTitle, -} from "@/components/ui/item"; import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext"; -import { ChevronRightIcon, HeartIcon, TimerIcon, TruckIcon } from "lucide-react"; +import { ChevronRightIcon } from "lucide-react"; +import type { Vehicle } from "@/payload-types"; +import { cn } from "@/lib/utils"; +import { categoryLabel, categoryPillClasses } from "@/lib/vehicles/categories"; interface VehicleCardProps { - vehicle: { - id: number; - name: string; - classname?: string | null; - category?: string[] | null; - description?: { - root: { - type: string; - children: { - type: any; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - image?: { url: string } | number | null; - construction?: { - materials?: { resource: { name: string } | number; amount: number }[]; - constructionTime?: number; - }; - combat?: { - maxHealth?: number; - maxSpeedOnRoad?: number; - }; - }; + vehicle: Vehicle; } -const categoryColors: Record = { - civilian: "bg-stone-500/20 text-stone-400", - utility: "bg-emerald-500/20 text-emerald-400", - transport: "bg-blue-500/20 text-blue-400", - drone: "bg-violet-500/20 text-violet-400", - weaponized: "bg-red-500/20 text-red-400", - static: "bg-slate-500/20 text-slate-400", - military: "bg-amber-500/20 text-amber-400", -}; - -const categoryLabels: Record = { - civilian: "Civilian", - utility: "Utility", - transport: "Transport", - drone: "Drone", - weaponized: "Weaponized", - static: "Static", - military: "Military", -}; - +/** + * Tactical dossier vehicle card (Battlefield-style registry tile): squared + * corners, classification strip, corner brackets, darkened cover imagery, + * faint grid, and a permanent readout footer. The reference implementation is + * CampaignCard (`intelligence/CampaignCard.tsx`); per its convention this card + * omits the opt-in glitch motion, keeping the treatment calm for a data grid. + */ export function VehicleCard({ vehicle }: VehicleCardProps) { - const image = vehicle.image && typeof vehicle.image === "object" ? vehicle.image : null; + const imageUrl = + vehicle.image && typeof vehicle.image === "object" ? (vehicle.image.url ?? null) : null; const description = vehicle.description ? convertLexicalToPlaintext({ data: vehicle.description }) : null; const truncatedDescription = - description && description.length > 150 ? description.slice(0, 150) + "…" : description; + description && description.length > 160 ? description.slice(0, 160) + "…" : description; - const materialCount = vehicle.construction?.materials?.length ?? 0; - const constructionTime = vehicle.construction?.constructionTime; - const maxHealth = vehicle.combat?.maxHealth; - const maxSpeed = vehicle.combat?.maxSpeedOnRoad; + const categories = vehicle.category ?? []; + // Vehicle stats are flat on the document (Payload tabs flatten into the + // parent), which the previous nested access got wrong and `as any` hid. + const materialCount = vehicle.materials?.length ?? 0; + const constructionTime = vehicle.constructionTime ?? null; + const maxHealth = vehicle.maxHealth ?? null; + const maxSpeed = vehicle.maxSpeedOnRoad ?? null; + + const refCode = String(vehicle.id).padStart(3, "0"); + const stripLabel = + categories.length > 0 + ? categories.map((c) => c.toUpperCase()).slice(0, 2).join(" / ") + : "UNCLASSIFIED"; + + const readoutCells = [ + maxHealth != null && { label: "Integrity", value: maxHealth.toLocaleString() }, + maxSpeed != null && { label: "Road", value: `${maxSpeed} km/h` }, + materialCount > 0 && { label: "Mats", value: String(materialCount) }, + constructionTime != null && { + label: "Build", + value: `${constructionTime} tick${constructionTime !== 1 ? "s" : ""}`, + }, + ].filter(Boolean) as { label: string; value: string }[]; return ( - - - -
- {image ? ( - - {vehicle.name} - - ) : ( - - - - )} - - {vehicle.classname && ( - {vehicle.classname} - )} - {vehicle.name} - -
-
- {vehicle.category?.map((cat) => ( + +
+ {/* Darkened cover imagery with gradient scrim */} +
); } diff --git a/src/lib/vehicles/categories.ts b/src/lib/vehicles/categories.ts new file mode 100644 index 00000000..663efe8f --- /dev/null +++ b/src/lib/vehicles/categories.ts @@ -0,0 +1,33 @@ +/** + * Single source of truth for vehicle category presentation. The card grid and + * the detail page both read from here so colors and labels never drift apart. + */ + +export const VEHICLE_CATEGORY_LABELS: Record = { + civilian: "Civilian", + utility: "Utility", + transport: "Transport", + drone: "Drone", + weaponized: "Weaponized", + static: "Static", + military: "Military", +}; + +/** Pill classes (Tailwind): -500/20 background with matching -400 text. */ +export const VEHICLE_CATEGORY_COLORS: Record = { + civilian: "bg-stone-500/20 text-stone-400", + utility: "bg-emerald-500/20 text-emerald-400", + transport: "bg-blue-500/20 text-blue-400", + drone: "bg-violet-500/20 text-violet-400", + weaponized: "bg-red-500/20 text-red-400", + static: "bg-slate-500/20 text-slate-400", + military: "bg-amber-500/20 text-amber-400", +}; + +export function categoryPillClasses(category: string): string { + return VEHICLE_CATEGORY_COLORS[category] ?? "bg-muted text-muted-foreground"; +} + +export function categoryLabel(category: string): string { + return VEHICLE_CATEGORY_LABELS[category] ?? category; +}