60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
// DocumentRow.tsx
|
|
// Generic row component for displaying any document type.
|
|
import { SessionRow } from "@/components/documents/session/SessionRow";
|
|
import { SecretRow } from "@/components/documents/secret/SecretRow";
|
|
import {
|
|
isNpc,
|
|
isScene,
|
|
isSecret,
|
|
isSession,
|
|
isTreasure,
|
|
type Document,
|
|
type Session,
|
|
} from "@/lib/types";
|
|
import { TreasureRow } from "./treasure/TreasureRow";
|
|
import { SceneRow } from "./scene/SceneRow";
|
|
import { NpcRow } from "./npc/NpcRow";
|
|
|
|
/**
|
|
* 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 DocumentRow = ({
|
|
document,
|
|
session,
|
|
}: {
|
|
document: Document;
|
|
session?: Session;
|
|
}) => {
|
|
if (isNpc(document)) {
|
|
return <NpcRow npc={document} />;
|
|
}
|
|
|
|
if (isSession(document)) {
|
|
return <SessionRow session={document} />;
|
|
}
|
|
|
|
if (isSecret(document)) {
|
|
return <SecretRow secret={document} session={session} />;
|
|
}
|
|
|
|
if (isScene(document)) {
|
|
return <SceneRow scene={document} />;
|
|
}
|
|
|
|
if (isTreasure(document)) {
|
|
return <TreasureRow treasure={document} session={session} />;
|
|
}
|
|
|
|
// 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>
|
|
);
|
|
};
|