= 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";
+};
diff --git a/src/routes/_authenticated/document.$documentId.tsx b/src/routes/_authenticated/document.$documentId.tsx
index 572fbb8..3f47269 100644
--- a/src/routes/_authenticated/document.$documentId.tsx
+++ b/src/routes/_authenticated/document.$documentId.tsx
@@ -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"
/>
+ Planned Secrets
+ {secrets && secrets.length > 0 ? (
+
+ {secrets.map((secret: any) => (
+ -
+ {secret.data?.secret?.text || (No secret text)}
+
+ ))}
+
+ ) : (
+ No planned secrets for this session.
+ )}
);
}