Changes all documents to have an explicit type
This commit is contained in:
@@ -1,64 +1,33 @@
|
||||
// DocumentRow.tsx
|
||||
// Generic row component for displaying any document type.
|
||||
import {
|
||||
isLocation,
|
||||
isMonster,
|
||||
isNpc,
|
||||
isScene,
|
||||
isSecret,
|
||||
isSession,
|
||||
isTreasure,
|
||||
type Document,
|
||||
} from "@/lib/types";
|
||||
import { type AnyDocument } from "@/lib/types";
|
||||
import { LocationPrintRow } from "./location/LocationPrintRow";
|
||||
import { MonsterPrintRow } from "./monsters/MonsterPrintRow";
|
||||
import { TreasurePrintRow } from "./treasure/TreasurePrintRow";
|
||||
import { SecretPrintRow } from "./secret/SecretPrintRow";
|
||||
import { NpcPrintRow } from "./npc/NpcPrintRow";
|
||||
import { ScenePrintRow } from "./scene/ScenePrintRow";
|
||||
import { SecretPrintRow } from "./secret/SecretPrintRow";
|
||||
import { SessionPrintRow } from "./session/SessionPrintRow";
|
||||
import { TreasurePrintRow } from "./treasure/TreasurePrintRow";
|
||||
|
||||
/**
|
||||
* Renders a row for any document type. Prioritizes Session, then Secret, then falls back to ID and creation time.
|
||||
* If rendering a SecretRow, uses the provided session prop if available.
|
||||
*/
|
||||
export const DocumentPrintRow = ({ document }: { document: Document }) => {
|
||||
if (isLocation(document)) {
|
||||
return <LocationPrintRow location={document} />;
|
||||
export const DocumentPrintRow = ({ document }: { document: AnyDocument }) => {
|
||||
switch (document.type) {
|
||||
case "location":
|
||||
return <LocationPrintRow location={document} />;
|
||||
case "monster":
|
||||
return <MonsterPrintRow monster={document} />;
|
||||
case "npc":
|
||||
return <NpcPrintRow npc={document} />;
|
||||
case "scene":
|
||||
return <ScenePrintRow scene={document} />;
|
||||
case "secret":
|
||||
return <SecretPrintRow secret={document} />;
|
||||
case "session":
|
||||
return <SessionPrintRow session={document} />;
|
||||
case "treasure":
|
||||
return <TreasurePrintRow treasure={document} />;
|
||||
}
|
||||
|
||||
if (isMonster(document)) {
|
||||
return <MonsterPrintRow monster={document} />;
|
||||
}
|
||||
|
||||
if (isNpc(document)) {
|
||||
return <NpcPrintRow npc={document} />;
|
||||
}
|
||||
|
||||
if (isSession(document)) {
|
||||
return <SessionPrintRow session={document} />;
|
||||
}
|
||||
|
||||
if (isSecret(document)) {
|
||||
return <SecretPrintRow secret={document} />;
|
||||
}
|
||||
|
||||
if (isScene(document)) {
|
||||
return <ScenePrintRow scene={document} />;
|
||||
}
|
||||
|
||||
if (isTreasure(document)) {
|
||||
return <TreasurePrintRow treasure={document} />;
|
||||
}
|
||||
|
||||
// Fallback: show ID and creation time
|
||||
return (
|
||||
<div>
|
||||
<div className="font-semibold text-lg text-slate-300">
|
||||
Unrecognized Document
|
||||
</div>
|
||||
<div className="text-slate-400 text-sm">ID: {document.id}</div>
|
||||
<div className="text-slate-400 text-sm">Created: {document.created}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user