1
0
Fork 0

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.
This commit is contained in:
Jason Fraley 2026-10-26 22:20:54 -04:00
parent acf47a75ea
commit f32afc6421
4 changed files with 170 additions and 142 deletions

View file

@ -29,9 +29,9 @@ export function VehiclesList({ vehicles }: { vehicles: Vehicle[] }) {
<>
<VehicleFilters categories={categories} onFilterChange={setSelectedCategory} />
{filtered.length > 0 ? (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{filtered.map((vehicle) => (
<VehicleCard key={vehicle.id} vehicle={vehicle as any} />
<VehicleCard key={vehicle.id} vehicle={vehicle} />
))}
</div>
) : (

View file

@ -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<string, string> = {
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<string, string> = {
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) => (
<span
key={cat}
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${categoryColors[cat] ?? "bg-muted text-muted-foreground"}`}
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${categoryPillClasses(cat)}`}
>
{cat}
{categoryLabel(cat)}
</span>
))}
</div>

View file

@ -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<string, string> = {
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<string, string> = {
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 (
<Link href={`/logistics/vehicles/${vehicle.id}`}>
<Item
variant="outline"
className="cursor-pointer group transition-all duration-200 hover:scale-[1.01] hover:[box-shadow:inset_0_2px_8px_rgba(255,255,255,0.33)]"
>
<ItemHeader>
<div className="flex items-center gap-2">
{image ? (
<ItemMedia variant="image">
<img src={image.url} alt={vehicle.name} className="size-full object-cover" />
</ItemMedia>
) : (
<ItemMedia variant="icon">
<TruckIcon />
</ItemMedia>
)}
<ItemTitle className="flex flex-col">
{vehicle.classname && (
<span className="font-mono text-xs text-muted-foreground">{vehicle.classname}</span>
)}
<span>{vehicle.name}</span>
</ItemTitle>
</div>
<div className="flex items-center gap-2">
{vehicle.category?.map((cat) => (
<Link
href={`/logistics/vehicles/${vehicle.id}`}
aria-label={`Open vehicle ${vehicle.name}`}
className="block rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
>
<article className="group relative flex min-h-[10rem] flex-col overflow-hidden rounded-none border border-border/70 bg-card transition-colors duration-300 hover:border-foreground/30">
{/* Darkened cover imagery with gradient scrim */}
<div aria-hidden="true" className="absolute inset-0">
{imageUrl ? (
<img
src={imageUrl}
alt=""
className="absolute inset-0 size-full object-cover opacity-15 transition-opacity duration-500 ease-out group-hover:opacity-25 motion-reduce:transition-none"
/>
) : (
<div className="absolute inset-0 bg-gradient-to-br from-muted to-muted/50 opacity-30" />
)}
<div className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/60 to-black/25" />
</div>
{/* Faint grid texture, constant opacity */}
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
style={{
backgroundImage:
"linear-gradient(to right, white 1px, transparent 1px), linear-gradient(to bottom, white 1px, transparent 1px)",
backgroundSize: "28px 28px",
}}
/>
{/* Classification strip */}
<div
aria-hidden="true"
className="absolute inset-x-0 top-0 z-20 flex items-center justify-between border-b border-white/15 bg-black/50 px-5 py-1.5 backdrop-blur-sm"
>
<span className="font-mono text-[9px] uppercase tracking-widest text-white/60">
Vehicle Registry // {stripLabel}
</span>
<span className="font-mono text-[9px] uppercase tracking-widest text-white/60">
REF {refCode}
</span>
</div>
{/* Corner brackets, brightening on hover */}
<div aria-hidden="true" className="pointer-events-none absolute inset-2 z-30">
<span className="absolute left-0 top-0 size-3 border-l border-t border-white/25 transition-colors duration-300 group-hover:border-white/60 motion-reduce:transition-none" />
<span className="absolute right-0 top-0 size-3 border-r border-t border-white/25 transition-colors duration-300 group-hover:border-white/60 motion-reduce:transition-none" />
<span className="absolute bottom-0 left-0 size-3 border-b border-l border-white/25 transition-colors duration-300 group-hover:border-white/60 motion-reduce:transition-none" />
<span className="absolute bottom-0 right-0 size-3 border-b border-r border-white/25 transition-colors duration-300 group-hover:border-white/60 motion-reduce:transition-none" />
</div>
{/* Body */}
<div className="relative z-10 flex flex-1 flex-col gap-1.5 px-5 pb-3 pt-8">
<div className="flex flex-wrap items-center gap-1.5">
{categories.map((cat) => (
<span
key={cat}
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${categoryColors[cat] ?? "bg-muted text-muted-foreground"}`}
className={cn(
"rounded-sm px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-widest",
categoryPillClasses(cat),
)}
>
{categoryLabels[cat] ?? cat}
{categoryLabel(cat)}
</span>
))}
</div>
</ItemHeader>
<ItemContent>
<div className="flex flex-col gap-3 w-full">
{truncatedDescription && (
<p className="text-sm text-muted-foreground line-clamp-2">{truncatedDescription}</p>
)}
<div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs text-muted-foreground">
{materialCount > 0 && (
<span className="flex items-center gap-1">
{materialCount} material{materialCount !== 1 ? "s" : ""}
{constructionTime != null && (
<>
, <TimerIcon className="size-3" />
{constructionTime} tick{constructionTime !== 1 ? "s" : ""}
</>
)}
</span>
)}
{maxHealth != null && (
<span className="flex items-center gap-1">
<HeartIcon className="size-3" />
{maxHealth.toLocaleString()} HP
</span>
)}
{maxSpeed != null && (
<span className="flex items-center gap-1">
<TruckIcon className="size-3" />
{maxSpeed} km/h
</span>
{vehicle.classname && (
<p className="font-mono text-[10px] uppercase tracking-widest text-white/50">
{vehicle.classname}
</p>
)}
<h3 className="text-balance text-lg font-bold leading-snug text-white drop-shadow">
{vehicle.name}
</h3>
{truncatedDescription && (
<p className="line-clamp-2 max-w-prose text-pretty text-xs leading-relaxed text-white/60 drop-shadow">
{truncatedDescription}
</p>
)}
</div>
{/* Permanent readout footer */}
<div className="relative z-10 mt-auto flex items-stretch border-t border-white/15 bg-black/60 backdrop-blur-sm">
{readoutCells.map((cell, i) => (
<div
key={cell.label}
className={cn(
"flex-1 px-3 py-1.5",
i !== readoutCells.length - 1 && "border-r border-white/15",
)}
>
<p className="font-mono text-xs tabular-nums text-white/80">{cell.value}</p>
<p className="text-[9px] uppercase tracking-wider text-white/50">{cell.label}</p>
</div>
</div>
</ItemContent>
<ItemDescription>{truncatedDescription ?? vehicle.classname ?? "Vehicle"}</ItemDescription>
<span className="text-xs text-muted-foreground group-hover:text-primary transition-colors flex items-center gap-1">
View details <ChevronRightIcon className="size-3" />
</span>
</Item>
))}
<span className="flex items-center gap-1 py-1.5 pl-3 pr-4 font-mono text-[9px] uppercase tracking-widest text-white/40 transition-colors group-hover:text-white/70 motion-reduce:transition-none">
Open
<ChevronRightIcon className="size-3" />
</span>
</div>
</article>
</Link>
);
}

View file

@ -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<string, string> = {
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<string, string> = {
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;
}