Adds relationships and loads secrets into the session details
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import type { RecordModel } from "pocketbase";
|
||||
|
||||
export type Id<T extends string> = string & { __type: T };
|
||||
|
||||
export type UserId = Id<"User">;
|
||||
export type CampaignId = Id<"Campaign">;
|
||||
export type DocumentId = Id<"Document">;
|
||||
|
||||
export type Campaign = {
|
||||
export type Campaign = RecordModel & {
|
||||
id: CampaignId;
|
||||
name: string;
|
||||
owner: UserId;
|
||||
};
|
||||
|
||||
export type Document = {
|
||||
export type Document = RecordModel & {
|
||||
id: DocumentId;
|
||||
campaign: Campaign;
|
||||
data: {};
|
||||
@@ -35,6 +37,12 @@ export type Secret = Document &
|
||||
"secret",
|
||||
{
|
||||
text: string;
|
||||
discoveredOn: ISO8601Date;
|
||||
discoveredOn: ISO8601Date | null;
|
||||
}
|
||||
>;
|
||||
|
||||
export type Relationship = RecordModel & {
|
||||
primary: DocumentId;
|
||||
secondary: DocumentId[];
|
||||
type: "plannedSecrets" | "discoveredIn";
|
||||
};
|
||||
|
||||
@@ -7,17 +7,29 @@ export const Route = createFileRoute(
|
||||
)({
|
||||
loader: async ({ params }) => {
|
||||
const doc = await pb.collection("documents").getOne(params.documentId);
|
||||
return { document: doc };
|
||||
// Fetch relationships where this document is the primary and type is "plannedSecrets"
|
||||
const relationships = await pb.collection("relationships").getFullList({
|
||||
filter: `primary = "${params.documentId}" && type = "plannedSecrets"`,
|
||||
});
|
||||
// Get all related secret document IDs from the secondary field
|
||||
const secretIds = relationships.map((rel: any) => rel.secondary);
|
||||
// Fetch all related secret documents
|
||||
let secrets: any[] = [];
|
||||
if (secretIds.length > 0) {
|
||||
secrets = await pb.collection("documents").getFullList({
|
||||
filter: secretIds.map(id => `id = "${id}"`).join(" || "),
|
||||
});
|
||||
}
|
||||
return { document: doc, secrets };
|
||||
},
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const { document } = Route.useLoaderData();
|
||||
const { document, secrets } = Route.useLoaderData();
|
||||
const strongStart = document?.data?.session?.strongStart || "";
|
||||
|
||||
async function handleSaveStrongStart(newValue: string) {
|
||||
// Update the document in Pocketbase
|
||||
await pb.collection("documents").update(document.id, {
|
||||
data: {
|
||||
...document.data,
|
||||
@@ -38,6 +50,18 @@ function RouteComponent() {
|
||||
placeholder="Enter a strong start for this session..."
|
||||
aria-label="Strong Start"
|
||||
/>
|
||||
<h3 className="text-lg font-semibold mt-8 mb-2 text-slate-200">Planned Secrets</h3>
|
||||
{secrets && secrets.length > 0 ? (
|
||||
<ul className="space-y-2">
|
||||
{secrets.map((secret: any) => (
|
||||
<li key={secret.id} className="bg-slate-800 rounded p-4 text-slate-100">
|
||||
{secret.data?.secret?.text || <span className="italic text-slate-400">(No secret text)</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<div className="text-slate-400">No planned secrets for this session.</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user