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:
parent
acf47a75ea
commit
f32afc6421
4 changed files with 170 additions and 142 deletions
|
|
@ -29,9 +29,9 @@ export function VehiclesList({ vehicles }: { vehicles: Vehicle[] }) {
|
||||||
<>
|
<>
|
||||||
<VehicleFilters categories={categories} onFilterChange={setSelectedCategory} />
|
<VehicleFilters categories={categories} onFilterChange={setSelectedCategory} />
|
||||||
{filtered.length > 0 ? (
|
{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) => (
|
{filtered.map((vehicle) => (
|
||||||
<VehicleCard key={vehicle.id} vehicle={vehicle as any} />
|
<VehicleCard key={vehicle.id} vehicle={vehicle} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import Link from "next/link";
|
||||||
import type { Resource, Structure, Technology } from "@/payload-types";
|
import type { Resource, Structure, Technology } from "@/payload-types";
|
||||||
import { RichText } from "@payloadcms/richtext-lexical/react";
|
import { RichText } from "@payloadcms/richtext-lexical/react";
|
||||||
import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext";
|
import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext";
|
||||||
|
import { categoryLabel, categoryPillClasses } from "@/lib/vehicles/categories";
|
||||||
import {
|
import {
|
||||||
ArrowLeftIcon,
|
ArrowLeftIcon,
|
||||||
BoxIcon,
|
BoxIcon,
|
||||||
|
|
@ -29,16 +30,6 @@ interface VehicleDetailPageProps {
|
||||||
params: Promise<{ id: string }>;
|
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> = {
|
const armorColors: Record<string, string> = {
|
||||||
none: "bg-muted text-muted-foreground",
|
none: "bg-muted text-muted-foreground",
|
||||||
light: "bg-green-500/20 text-green-400",
|
light: "bg-green-500/20 text-green-400",
|
||||||
|
|
@ -106,9 +97,9 @@ export default async function VehicleDetailPage({ params }: VehicleDetailPagePro
|
||||||
{(vehicle.category ?? []).map((cat) => (
|
{(vehicle.category ?? []).map((cat) => (
|
||||||
<span
|
<span
|
||||||
key={cat}
|
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>
|
</span>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,155 +1,159 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
|
||||||
Item,
|
|
||||||
ItemContent,
|
|
||||||
ItemDescription,
|
|
||||||
ItemHeader,
|
|
||||||
ItemMedia,
|
|
||||||
ItemTitle,
|
|
||||||
} from "@/components/ui/item";
|
|
||||||
import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext";
|
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 {
|
interface VehicleCardProps {
|
||||||
vehicle: {
|
vehicle: 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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoryColors: Record<string, string> = {
|
/**
|
||||||
civilian: "bg-stone-500/20 text-stone-400",
|
* Tactical dossier vehicle card (Battlefield-style registry tile): squared
|
||||||
utility: "bg-emerald-500/20 text-emerald-400",
|
* corners, classification strip, corner brackets, darkened cover imagery,
|
||||||
transport: "bg-blue-500/20 text-blue-400",
|
* faint grid, and a permanent readout footer. The reference implementation is
|
||||||
drone: "bg-violet-500/20 text-violet-400",
|
* CampaignCard (`intelligence/CampaignCard.tsx`); per its convention this card
|
||||||
weaponized: "bg-red-500/20 text-red-400",
|
* omits the opt-in glitch motion, keeping the treatment calm for a data grid.
|
||||||
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",
|
|
||||||
};
|
|
||||||
|
|
||||||
export function VehicleCard({ vehicle }: VehicleCardProps) {
|
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
|
const description = vehicle.description
|
||||||
? convertLexicalToPlaintext({ data: vehicle.description })
|
? convertLexicalToPlaintext({ data: vehicle.description })
|
||||||
: null;
|
: null;
|
||||||
const truncatedDescription =
|
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 categories = vehicle.category ?? [];
|
||||||
const constructionTime = vehicle.construction?.constructionTime;
|
// Vehicle stats are flat on the document (Payload tabs flatten into the
|
||||||
const maxHealth = vehicle.combat?.maxHealth;
|
// parent), which the previous nested access got wrong and `as any` hid.
|
||||||
const maxSpeed = vehicle.combat?.maxSpeedOnRoad;
|
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 (
|
return (
|
||||||
<Link href={`/logistics/vehicles/${vehicle.id}`}>
|
<Link
|
||||||
<Item
|
href={`/logistics/vehicles/${vehicle.id}`}
|
||||||
variant="outline"
|
aria-label={`Open vehicle ${vehicle.name}`}
|
||||||
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)]"
|
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"
|
||||||
>
|
>
|
||||||
<ItemHeader>
|
<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">
|
||||||
<div className="flex items-center gap-2">
|
{/* Darkened cover imagery with gradient scrim */}
|
||||||
{image ? (
|
<div aria-hidden="true" className="absolute inset-0">
|
||||||
<ItemMedia variant="image">
|
{imageUrl ? (
|
||||||
<img src={image.url} alt={vehicle.name} className="size-full object-cover" />
|
<img
|
||||||
</ItemMedia>
|
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"
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ItemMedia variant="icon">
|
<div className="absolute inset-0 bg-gradient-to-br from-muted to-muted/50 opacity-30" />
|
||||||
<TruckIcon />
|
|
||||||
</ItemMedia>
|
|
||||||
)}
|
)}
|
||||||
<ItemTitle className="flex flex-col">
|
<div className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/60 to-black/25" />
|
||||||
{vehicle.classname && (
|
|
||||||
<span className="font-mono text-xs text-muted-foreground">{vehicle.classname}</span>
|
|
||||||
)}
|
|
||||||
<span>{vehicle.name}</span>
|
|
||||||
</ItemTitle>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{vehicle.category?.map((cat) => (
|
{/* 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
|
<span
|
||||||
key={cat}
|
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>
|
</span>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</ItemHeader>
|
{vehicle.classname && (
|
||||||
<ItemContent>
|
<p className="font-mono text-[10px] uppercase tracking-widest text-white/50">
|
||||||
<div className="flex flex-col gap-3 w-full">
|
{vehicle.classname}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<h3 className="text-balance text-lg font-bold leading-snug text-white drop-shadow">
|
||||||
|
{vehicle.name}
|
||||||
|
</h3>
|
||||||
{truncatedDescription && (
|
{truncatedDescription && (
|
||||||
<p className="text-sm text-muted-foreground line-clamp-2">{truncatedDescription}</p>
|
<p className="line-clamp-2 max-w-prose text-pretty text-xs leading-relaxed text-white/60 drop-shadow">
|
||||||
)}
|
{truncatedDescription}
|
||||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs text-muted-foreground">
|
</p>
|
||||||
{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>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</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="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">
|
||||||
<span className="text-xs text-muted-foreground group-hover:text-primary transition-colors flex items-center gap-1">
|
Open
|
||||||
View details <ChevronRightIcon className="size-3" />
|
<ChevronRightIcon className="size-3" />
|
||||||
</span>
|
</span>
|
||||||
</Item>
|
</div>
|
||||||
|
</article>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
src/lib/vehicles/categories.ts
Normal file
33
src/lib/vehicles/categories.ts
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue