- Add campaigns list page with campaign cards - Add missions list page with filtering and mission cards - Add factions list page with faction cards - Add mission detail components: briefing, comms, factions, logistics, objectives, roles - Add MissionFilters for status and type filtering
321 lines
12 KiB
TypeScript
321 lines
12 KiB
TypeScript
import config from "@payload-config";
|
|
import { getPayload } from "payload";
|
|
import { notFound } from "next/navigation";
|
|
import Link from "next/link";
|
|
import type { Campaign, Faction, Mission } from "@/payload-types";
|
|
import { RichText } from "@payloadcms/richtext-lexical/react";
|
|
import {
|
|
ArrowLeftIcon,
|
|
CalendarDaysIcon,
|
|
ChevronRightIcon,
|
|
CrosshairIcon,
|
|
ShieldIcon,
|
|
TargetIcon,
|
|
UsersIcon,
|
|
} from "lucide-react";
|
|
import {
|
|
Item,
|
|
ItemContent,
|
|
ItemDescription,
|
|
ItemHeader,
|
|
ItemTitle,
|
|
} from "@/components/ui/item";
|
|
|
|
interface CampaignDetailPageProps {
|
|
params: Promise<{ id: string }>;
|
|
}
|
|
|
|
const statusColors: Record<string, string> = {
|
|
concept: "bg-muted text-muted-foreground",
|
|
inProgress: "bg-blue-500/20 text-blue-400",
|
|
completed: "bg-emerald-500/20 text-emerald-400",
|
|
};
|
|
|
|
const factionTypeColors: Record<string, string> = {
|
|
majorFaction: "bg-blue-500/20 text-blue-400",
|
|
minorFaction: "bg-muted text-muted-foreground",
|
|
corporation: "bg-amber-500/20 text-amber-400",
|
|
special: "bg-purple-500/20 text-purple-400",
|
|
};
|
|
|
|
const missionStatusColors: Record<string, string> = {
|
|
Concept: "bg-muted text-muted-foreground",
|
|
Planning: "bg-muted text-muted-foreground",
|
|
Ready: "bg-blue-500/20 text-blue-400",
|
|
Scheduled: "bg-amber-500/20 text-amber-400",
|
|
Active: "bg-green-500/20 text-green-400",
|
|
Completed: "bg-emerald-500/20 text-emerald-400",
|
|
Cancelled: "bg-red-500/20 text-red-400",
|
|
};
|
|
|
|
export default async function CampaignDetailPage({
|
|
params,
|
|
}: CampaignDetailPageProps) {
|
|
const { id } = await params;
|
|
const payload = await getPayload({ config });
|
|
|
|
const campaign = await payload
|
|
.findByID({
|
|
collection: "campaigns",
|
|
id: Number(id),
|
|
depth: 0,
|
|
})
|
|
.catch(() => null);
|
|
|
|
if (!campaign) {
|
|
notFound();
|
|
}
|
|
|
|
const [missionsRes, factionsRes] = await Promise.all([
|
|
payload
|
|
.find({
|
|
collection: "missions",
|
|
where: { "classification.campaign": { equals: campaign.id } },
|
|
sort: "-classification.startDateTime",
|
|
limit: 100,
|
|
depth: 1,
|
|
select: {
|
|
name: true,
|
|
codeName: true,
|
|
summary: true,
|
|
operationType: true,
|
|
classification: true,
|
|
ownershipAndStatus: true,
|
|
missionRoles: true,
|
|
},
|
|
})
|
|
.catch(() => ({ docs: [] })),
|
|
payload.find({
|
|
collection: "factions",
|
|
where: { associatedCampaigns: { equals: campaign.id } },
|
|
limit: 100,
|
|
depth: 0,
|
|
select: { name: true, type: true, description: true },
|
|
}),
|
|
]);
|
|
|
|
const missions = missionsRes.docs as Mission[];
|
|
const factions = factionsRes.docs as Faction[];
|
|
|
|
const startDate = campaign.startDate
|
|
? new Date(campaign.startDate).toLocaleDateString("en-US", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
})
|
|
: null;
|
|
const endDate = campaign.endDate
|
|
? new Date(campaign.endDate).toLocaleDateString("en-US", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
})
|
|
: null;
|
|
|
|
// Mission status breakdown
|
|
const statusCounts: Record<string, number> = {};
|
|
for (const m of missions) {
|
|
const s = m.ownershipAndStatus.status;
|
|
statusCounts[s] = (statusCounts[s] ?? 0) + 1;
|
|
}
|
|
|
|
return (
|
|
<div className="p-5 flex flex-col gap-6 max-w-7xl">
|
|
<Link
|
|
href="/intelligence/campaigns"
|
|
className="text-sm text-muted-foreground hover:text-primary transition-colors flex items-center gap-1 w-fit"
|
|
>
|
|
<ArrowLeftIcon className="size-3" />
|
|
Back to Campaigns
|
|
</Link>
|
|
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<ShieldIcon className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">{campaign.name}</h1>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<span
|
|
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${statusColors[campaign.status] ?? "bg-muted text-muted-foreground"}`}
|
|
>
|
|
{campaign.status === "inProgress"
|
|
? "In Progress"
|
|
: campaign.status.charAt(0).toUpperCase() +
|
|
campaign.status.slice(1)}
|
|
</span>
|
|
{startDate && (
|
|
<span className="text-xs text-muted-foreground flex items-center gap-1">
|
|
<CalendarDaysIcon className="size-3" />
|
|
{startDate}
|
|
{endDate ? ` — ${endDate}` : " — Present"}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<p className="text-sm text-muted-foreground">{campaign.summary}</p>
|
|
|
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
|
{/* ── Main Content (2/3) ──────────────────────────── */}
|
|
<div className="xl:col-span-2 flex flex-col gap-6">
|
|
{campaign.description && (
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<ItemTitle>Description</ItemTitle>
|
|
</ItemHeader>
|
|
<ItemContent className="prose-invert prose-sm max-w-none [&_p]:mb-2 [&_ul]:list-disc [&_ul]:ml-4 [&_ol]:list-decimal [&_ol]:ml-4 [&_strong]:text-foreground [&_em]:italic">
|
|
<RichText data={campaign.description} />
|
|
</ItemContent>
|
|
</Item>
|
|
)}
|
|
|
|
<section className="flex flex-col gap-3">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="text-sm font-semibold uppercase tracking-wider text-muted-foreground">
|
|
Missions
|
|
</h2>
|
|
<span className="text-xs text-muted-foreground">
|
|
{missions.length} mission{missions.length !== 1 ? "s" : ""}
|
|
</span>
|
|
</div>
|
|
{missions.length > 0 ? (
|
|
<div className="flex flex-col gap-2">
|
|
{missions.map((mission) => (
|
|
<Link
|
|
key={mission.id}
|
|
href={`/intelligence/missions/${mission.id}`}
|
|
>
|
|
<Item
|
|
variant="outline"
|
|
className="cursor-pointer group transition-all duration-200 hover:scale-[1.01]"
|
|
>
|
|
<ItemHeader>
|
|
<div className="flex flex-col gap-0.5">
|
|
<span className="font-mono text-xs text-muted-foreground">
|
|
{mission.codeName}
|
|
</span>
|
|
<ItemTitle>{mission.name}</ItemTitle>
|
|
</div>
|
|
<span
|
|
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${
|
|
missionStatusColors[
|
|
mission.ownershipAndStatus.status
|
|
] ?? "bg-muted text-muted-foreground"
|
|
}`}
|
|
>
|
|
{mission.ownershipAndStatus.status}
|
|
</span>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
<ItemDescription className="line-clamp-1">
|
|
{mission.summary}
|
|
</ItemDescription>
|
|
</ItemContent>
|
|
</Item>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<Item variant="muted">
|
|
<ItemContent>
|
|
<p className="text-sm text-muted-foreground italic">
|
|
No missions in this campaign yet.
|
|
</p>
|
|
</ItemContent>
|
|
</Item>
|
|
)}
|
|
</section>
|
|
</div>
|
|
|
|
{/* ── Right Sidebar (1/3) ─────────────────────────── */}
|
|
<div className="flex flex-col gap-4">
|
|
{/* Campaign Stats */}
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<div className="flex items-center gap-2">
|
|
<TargetIcon className="size-4 text-muted-foreground" />
|
|
<ItemTitle>Campaign Stats</ItemTitle>
|
|
</div>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex justify-between text-sm">
|
|
<span className="text-muted-foreground">Total Missions</span>
|
|
<span className="font-semibold">{missions.length}</span>
|
|
</div>
|
|
{Object.entries(statusCounts).map(([status, count]) => (
|
|
<div key={status} className="flex justify-between text-sm">
|
|
<span className="flex items-center gap-1.5">
|
|
<span
|
|
className={`size-2 rounded-full ${missionStatusColors[status]?.split(" ")[0] ?? "bg-muted"}`}
|
|
/>
|
|
<span className="text-muted-foreground">{status}</span>
|
|
</span>
|
|
<span className="font-mono">{count}</span>
|
|
</div>
|
|
))}
|
|
{campaign.startDate && (
|
|
<div className="flex justify-between text-sm pt-1 border-t border-border/50">
|
|
<span className="text-muted-foreground">Duration</span>
|
|
<span>
|
|
{startDate}
|
|
{endDate ? ` — ${endDate}` : " — Present"}
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</ItemContent>
|
|
</Item>
|
|
|
|
{/* Faction Roster */}
|
|
{factions.length > 0 && (
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<div className="flex items-center gap-2">
|
|
<UsersIcon className="size-4 text-muted-foreground" />
|
|
<ItemTitle>Faction Roster</ItemTitle>
|
|
</div>
|
|
<Link
|
|
href="/intelligence/factions"
|
|
className="text-xs text-muted-foreground hover:text-primary transition-colors"
|
|
>
|
|
View all
|
|
</Link>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
<div className="flex flex-col gap-2">
|
|
{factions.map((faction) => (
|
|
<Link
|
|
key={faction.id}
|
|
href="/intelligence/factions"
|
|
className="flex items-center gap-3 p-1.5 rounded-md hover:bg-muted/50 transition-colors group"
|
|
>
|
|
<ShieldIcon className="size-4 text-muted-foreground shrink-0" />
|
|
<div className="flex flex-col gap-0.5 min-w-0 flex-1">
|
|
<span className="text-sm font-medium truncate group-hover:text-primary transition-colors">
|
|
{faction.name}
|
|
</span>
|
|
<span
|
|
className={`text-[10px] font-semibold uppercase tracking-wider px-1 py-0.5 rounded w-fit ${factionTypeColors[faction.type] ?? "bg-muted text-muted-foreground"}`}
|
|
>
|
|
{faction.type === "majorFaction"
|
|
? "Major"
|
|
: faction.type === "minorFaction"
|
|
? "Minor"
|
|
: faction.type}
|
|
</span>
|
|
</div>
|
|
<ChevronRightIcon className="size-3 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity shrink-0" />
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</ItemContent>
|
|
</Item>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|