RichText authored in the admin panel was rendered as plain text on the public site: headings/lists/quotes were flattened by Tailwind preflight (no @tailwindcss/typography installed), and Payload's default JSX converter ignored text colours. - src/lib/lexical: shared editor factory (ptfLexicalEditor) + shared colour palette (textState) + colour converter (richTextConverters) - RichTextView: canonical .lexical-content renderer (colour-aware), swapped into every frontend render site - All rich-text editors route through the factory, so every field inherits the coloured editor (incl. the previously-unedited ones) - .lexical-content CSS extended with checklist/table/heading rules, wrapped in @layer components so per-page utilities still override; dropped the now-dead per-page prose hacks - Remove the now-dead briefingConverters in favour of the shared converter; add tests/int/rich-text-view.int.spec.ts
268 lines
10 KiB
TypeScript
268 lines
10 KiB
TypeScript
"use client";
|
||
|
||
import { useCallback, useEffect, useState } from "react";
|
||
import Link from "next/link";
|
||
import { X, ExternalLinkIcon } from "lucide-react";
|
||
import { Button } from "@/components/ui/button";
|
||
import { CapacityBar } from "@/components/frontend/storage/CapacityBar";
|
||
import { StorageRules } from "@/components/frontend/storage/StorageRules";
|
||
import { StructureStorageView } from "@/components/frontend/storage/StructureStorageView";
|
||
import { StaffRoster } from "@/components/frontend/baseManagement/StaffRoster";
|
||
import { UpgradeCard } from "@/components/frontend/baseManagement/UpgradeCard";
|
||
import { ConstructionPanel } from "@/components/frontend/baseManagement/ConstructionPanel";
|
||
import { ProductionPanel } from "@/components/frontend/baseManagement/ProductionPanel";
|
||
import { SlotsPanel } from "@/components/frontend/baseManagement/SlotsPanel";
|
||
import { getStructureDetail } from "@/app/(frontend)/logistics/structures/[id]/detail";
|
||
import type { StructureDetailData } from "@/app/(frontend)/logistics/structures/[id]/detail-data";
|
||
import { RichTextView } from "@/components/frontend/RichTextView";
|
||
import { useGameTick } from "@/hooks/useGameTick";
|
||
import { BoxIcon, CoinsIcon, MapPinIcon, WrenchIcon } from "lucide-react";
|
||
import {
|
||
Item,
|
||
ItemContent,
|
||
ItemDescription,
|
||
ItemHeader,
|
||
ItemMedia,
|
||
ItemTitle,
|
||
} from "@/components/ui/item";
|
||
|
||
export function StructureDetailDrawer({
|
||
structureId,
|
||
onClose,
|
||
}: {
|
||
structureId: number;
|
||
onClose: () => void;
|
||
}) {
|
||
const [data, setData] = useState<StructureDetailData | null>(null);
|
||
const [error, setError] = useState<string | null>(null);
|
||
|
||
const load = useCallback(async () => {
|
||
const result = await getStructureDetail(structureId);
|
||
if (result.success && result.data) {
|
||
setData(result.data);
|
||
setError(null);
|
||
} else {
|
||
setError(result.error ?? "Failed to load structure.");
|
||
}
|
||
}, [structureId]);
|
||
|
||
useEffect(() => {
|
||
void load();
|
||
}, [load]);
|
||
|
||
useGameTick(load);
|
||
|
||
const structure = data?.structure ?? null;
|
||
const blueprint = data?.blueprint ?? null;
|
||
|
||
return (
|
||
<div className="absolute inset-y-0 right-0 z-[1200] flex w-[480px] max-w-[94vw] flex-col border-l border-white/15 bg-[#080a0e]/95 backdrop-blur-md">
|
||
<div className="flex items-center justify-between gap-4 border-b border-white/15 bg-black/60 px-3 py-1.5">
|
||
<span className="font-mono text-[9px] uppercase tracking-[0.2em] text-white/60">
|
||
Structure Dossier // Preview
|
||
</span>
|
||
<span className="font-mono text-[9px] uppercase tracking-[0.2em] text-white/60">
|
||
REF {String(structureId).padStart(3, "0")}
|
||
</span>
|
||
<button
|
||
onClick={onClose}
|
||
aria-label="Close preview"
|
||
className="rounded-none p-1 text-white/50 transition-colors hover:text-white"
|
||
>
|
||
<X className="size-4" />
|
||
</button>
|
||
</div>
|
||
|
||
<div className="min-h-0 flex-1 overflow-y-auto p-3">
|
||
{!data && !error && (
|
||
<p className="p-4 font-mono text-[10px] uppercase tracking-[0.2em] text-white/50">
|
||
Loading dossier...
|
||
</p>
|
||
)}
|
||
{error && (
|
||
<div className="rounded-none border border-red-500/40 bg-red-950/60 p-3 text-xs text-red-200">
|
||
{error}
|
||
</div>
|
||
)}
|
||
|
||
{data && structure && blueprint && (
|
||
<div className="flex flex-col gap-4">
|
||
<div className="flex flex-col gap-2">
|
||
{data.imageUrl && (
|
||
<div className="relative overflow-hidden rounded-none border border-white/15">
|
||
<img
|
||
src={data.imageUrl}
|
||
alt={structure.name}
|
||
className="h-36 w-full object-cover"
|
||
/>
|
||
<div className="absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent" />
|
||
</div>
|
||
)}
|
||
<div className="font-mono text-[10px] uppercase tracking-[0.14em] text-white/60">
|
||
{blueprint.name}
|
||
{data.gates.canManage ? " // managed by you" : ""}
|
||
</div>
|
||
<div className="text-base font-semibold text-white/95">{structure.name}</div>
|
||
{data.description ? (
|
||
<RichTextView data={data.description} className="text-xs text-muted-foreground" />
|
||
) : null}
|
||
<div className="flex gap-2">
|
||
<Button
|
||
asChild
|
||
size="sm"
|
||
variant="outline"
|
||
className="h-7 flex-1 rounded-none px-2 font-mono text-[10px] uppercase tracking-[0.2em]"
|
||
>
|
||
<Link href={`/logistics/structures/${structure.id}`} target="_blank">
|
||
<ExternalLinkIcon className="size-3" />
|
||
Full Page
|
||
</Link>
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-1 gap-3">
|
||
<Item variant="outline">
|
||
<ItemHeader>
|
||
<ItemTitle className="flex items-center gap-2">
|
||
<BoxIcon className="size-4 text-muted-foreground" />
|
||
Storage Capacity
|
||
</ItemTitle>
|
||
</ItemHeader>
|
||
<ItemContent>
|
||
<CapacityBar
|
||
utilization={data.derived.utilization}
|
||
currentMass={data.derived.currentMass}
|
||
maxMass={blueprint.maxCapacityMass ?? null}
|
||
/>
|
||
</ItemContent>
|
||
</Item>
|
||
|
||
<Item variant="outline">
|
||
<ItemHeader>
|
||
<ItemTitle className="flex items-center gap-2">
|
||
<CoinsIcon className="size-4 text-muted-foreground" />
|
||
Total Value
|
||
</ItemTitle>
|
||
</ItemHeader>
|
||
<ItemContent>
|
||
<div className="flex items-center gap-2">
|
||
<span className="text-xl font-bold">
|
||
{data.derived.totalValue.toLocaleString()}
|
||
</span>
|
||
<span className="text-xs text-muted-foreground">base value</span>
|
||
</div>
|
||
</ItemContent>
|
||
</Item>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 gap-2">
|
||
{structure.coordinates && (
|
||
<Item variant="muted" size="sm">
|
||
<ItemMedia variant="icon">
|
||
<MapPinIcon />
|
||
</ItemMedia>
|
||
<ItemContent>
|
||
<ItemTitle>Coordinates</ItemTitle>
|
||
<ItemDescription>
|
||
{structure.coordinates[0].toFixed(0)}, {structure.coordinates[1].toFixed(0)}
|
||
</ItemDescription>
|
||
</ItemContent>
|
||
</Item>
|
||
)}
|
||
{data.derived.gridSlots !== null && (
|
||
<Item variant="muted" size="sm">
|
||
<ItemMedia variant="icon">
|
||
<BoxIcon />
|
||
</ItemMedia>
|
||
<ItemContent>
|
||
<ItemTitle>Grid</ItemTitle>
|
||
<ItemDescription>
|
||
{blueprint.xSize}×{blueprint.ySize} ({data.derived.gridSlots} slots)
|
||
</ItemDescription>
|
||
</ItemContent>
|
||
</Item>
|
||
)}
|
||
{blueprint.maxCapacityMass && (
|
||
<Item variant="muted" size="sm">
|
||
<ItemMedia variant="icon">
|
||
<BoxIcon />
|
||
</ItemMedia>
|
||
<ItemContent>
|
||
<ItemTitle>Max Capacity</ItemTitle>
|
||
<ItemDescription>
|
||
{blueprint.maxCapacityMass.toLocaleString()} kg (mass)
|
||
</ItemDescription>
|
||
</ItemContent>
|
||
</Item>
|
||
)}
|
||
{blueprint.maxHealth && (
|
||
<Item variant="muted" size="sm">
|
||
<ItemMedia variant="icon">
|
||
<WrenchIcon />
|
||
</ItemMedia>
|
||
<ItemContent>
|
||
<ItemTitle>Max Health</ItemTitle>
|
||
<ItemDescription>{blueprint.maxHealth.toLocaleString()}</ItemDescription>
|
||
</ItemContent>
|
||
</Item>
|
||
)}
|
||
</div>
|
||
|
||
<UpgradeCard gameStructureId={structure.id} upgrade={data.upgrade} />
|
||
|
||
<ConstructionPanel
|
||
status={structure.constructionStatus ?? "complete"}
|
||
startedAt={structure.constructionStartedAt ?? null}
|
||
completesAt={structure.constructionCompletesAt ?? null}
|
||
durationMinutes={blueprint.constructionDurationMinutes ?? null}
|
||
materials={data.derived.constructionMaterials}
|
||
crew={data.derived.constructionCrew}
|
||
/>
|
||
|
||
<ProductionPanel
|
||
gameStructureId={structure.id}
|
||
complete={(structure.constructionStatus ?? "complete") === "complete"}
|
||
paused={data.production.paused}
|
||
stallReason={data.production.stallReason}
|
||
inputs={data.production.inputs}
|
||
outputs={data.production.outputs}
|
||
canManage={data.gates.canManage}
|
||
/>
|
||
|
||
<SlotsPanel
|
||
gameStructureId={structure.id}
|
||
slots={data.modules.slots}
|
||
installed={data.modules.installed}
|
||
options={data.modules.options}
|
||
canManage={data.gates.canManage}
|
||
/>
|
||
|
||
<StaffRoster
|
||
structure={data.staffing.structureStaffing}
|
||
staff={data.staffing.staff}
|
||
classifications={data.staffing.classifications}
|
||
npcs={data.staffing.npcs}
|
||
canManage={data.gates.canManage}
|
||
hiringEnabled={data.hiring.enabled}
|
||
hiringDisabledMessage={data.hiring.disabledMessage}
|
||
currencyConfig={data.currencyConfig}
|
||
/>
|
||
|
||
<StructureStorageView
|
||
structure={structure}
|
||
canMutate={data.gates.canManageStorage}
|
||
canArrange={data.gates.canTransferStorage}
|
||
/>
|
||
|
||
<StorageRules
|
||
allowedStorage={blueprint.allowedStorage}
|
||
prohibitedStorage={blueprint.prohibitedStorage}
|
||
restrictToAllowed={blueprint.restrictToAllowed}
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|