Adds relationships and loads secrets into the session details
This commit is contained in:
100
pb_migrations/1748471315_created_relationships.js
Normal file
100
pb_migrations/1748471315_created_relationships.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
|
migrate((app) => {
|
||||||
|
const collection = new Collection({
|
||||||
|
"createRule": null,
|
||||||
|
"deleteRule": null,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "[a-z0-9]{15}",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text3208210256",
|
||||||
|
"max": 15,
|
||||||
|
"min": 15,
|
||||||
|
"name": "id",
|
||||||
|
"pattern": "^[a-z0-9]+$",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": true,
|
||||||
|
"required": true,
|
||||||
|
"system": true,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"collectionId": "pbc_3332084752",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "relation390457990",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "primary",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"collectionId": "pbc_3332084752",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "relation458454037",
|
||||||
|
"maxSelect": 999,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "secondary",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "select2363381545",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"name": "type",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "select",
|
||||||
|
"values": [
|
||||||
|
"plannedFor",
|
||||||
|
"discoveredIn"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate2990389176",
|
||||||
|
"name": "created",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": false,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate3332085495",
|
||||||
|
"name": "updated",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": true,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "pbc_617371094",
|
||||||
|
"indexes": [
|
||||||
|
"CREATE INDEX `idx_relationships_documents` ON `relationships` (\n `primary`,\n `secondary`\n)",
|
||||||
|
"CREATE INDEX `idx_relationships_types` ON `relationships` (`type`)"
|
||||||
|
],
|
||||||
|
"listRule": null,
|
||||||
|
"name": "relationships",
|
||||||
|
"system": false,
|
||||||
|
"type": "base",
|
||||||
|
"updateRule": null,
|
||||||
|
"viewRule": null
|
||||||
|
});
|
||||||
|
|
||||||
|
return app.save(collection);
|
||||||
|
}, (app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094");
|
||||||
|
|
||||||
|
return app.delete(collection);
|
||||||
|
})
|
||||||
42
pb_migrations/1748471393_updated_relationships.js
Normal file
42
pb_migrations/1748471393_updated_relationships.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
|
migrate((app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update field
|
||||||
|
collection.fields.addAt(3, new Field({
|
||||||
|
"hidden": false,
|
||||||
|
"id": "select2363381545",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"name": "type",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "select",
|
||||||
|
"values": [
|
||||||
|
"discoveredIn",
|
||||||
|
"plannedSecrets"
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
}, (app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update field
|
||||||
|
collection.fields.addAt(3, new Field({
|
||||||
|
"hidden": false,
|
||||||
|
"id": "select2363381545",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"name": "type",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "select",
|
||||||
|
"values": [
|
||||||
|
"plannedFor",
|
||||||
|
"discoveredIn"
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
})
|
||||||
27
pb_migrations/1748471513_updated_relationships.js
Normal file
27
pb_migrations/1748471513_updated_relationships.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
|
migrate((app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
unmarshal({
|
||||||
|
"indexes": [
|
||||||
|
"CREATE INDEX `idx_relationships_documents` ON `relationships` (\n `primary`,\n `secondary`\n)",
|
||||||
|
"CREATE INDEX `idx_relationships_types` ON `relationships` (`type`)",
|
||||||
|
"CREATE UNIQUE INDEX `idx_relationships_primary_type` ON `relationships` (\n `primary`,\n `type`\n)"
|
||||||
|
]
|
||||||
|
}, collection)
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
}, (app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
unmarshal({
|
||||||
|
"indexes": [
|
||||||
|
"CREATE INDEX `idx_relationships_documents` ON `relationships` (\n `primary`,\n `secondary`\n)",
|
||||||
|
"CREATE INDEX `idx_relationships_types` ON `relationships` (`type`)"
|
||||||
|
]
|
||||||
|
}, collection)
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
})
|
||||||
34
pb_migrations/1748471982_updated_documents.js
Normal file
34
pb_migrations/1748471982_updated_documents.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
|
migrate((app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_3332084752")
|
||||||
|
|
||||||
|
// update field
|
||||||
|
collection.fields.addAt(2, new Field({
|
||||||
|
"hidden": false,
|
||||||
|
"id": "json2918445923",
|
||||||
|
"maxSize": 0,
|
||||||
|
"name": "data",
|
||||||
|
"presentable": true,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "json"
|
||||||
|
}))
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
}, (app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_3332084752")
|
||||||
|
|
||||||
|
// update field
|
||||||
|
collection.fields.addAt(2, new Field({
|
||||||
|
"hidden": false,
|
||||||
|
"id": "json2918445923",
|
||||||
|
"maxSize": 0,
|
||||||
|
"name": "data",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "json"
|
||||||
|
}))
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
})
|
||||||
28
pb_migrations/1748472065_updated_relationships.js
Normal file
28
pb_migrations/1748472065_updated_relationships.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
|
migrate((app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
unmarshal({
|
||||||
|
"createRule": "",
|
||||||
|
"deleteRule": "@request.auth.id = primary.campaign.owner.id",
|
||||||
|
"listRule": "@request.auth.id = primary.campaign.owner.id",
|
||||||
|
"updateRule": "@request.auth.id = primary.campaign.owner.id",
|
||||||
|
"viewRule": "@request.auth.id = primary.campaign.owner.id"
|
||||||
|
}, collection)
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
}, (app) => {
|
||||||
|
const collection = app.findCollectionByNameOrId("pbc_617371094")
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
unmarshal({
|
||||||
|
"createRule": null,
|
||||||
|
"deleteRule": null,
|
||||||
|
"listRule": null,
|
||||||
|
"updateRule": null,
|
||||||
|
"viewRule": null
|
||||||
|
}, collection)
|
||||||
|
|
||||||
|
return app.save(collection)
|
||||||
|
})
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
|
import type { RecordModel } from "pocketbase";
|
||||||
|
|
||||||
export type Id<T extends string> = string & { __type: T };
|
export type Id<T extends string> = string & { __type: T };
|
||||||
|
|
||||||
export type UserId = Id<"User">;
|
export type UserId = Id<"User">;
|
||||||
export type CampaignId = Id<"Campaign">;
|
export type CampaignId = Id<"Campaign">;
|
||||||
export type DocumentId = Id<"Document">;
|
export type DocumentId = Id<"Document">;
|
||||||
|
|
||||||
export type Campaign = {
|
export type Campaign = RecordModel & {
|
||||||
id: CampaignId;
|
id: CampaignId;
|
||||||
name: string;
|
name: string;
|
||||||
owner: UserId;
|
owner: UserId;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Document = {
|
export type Document = RecordModel & {
|
||||||
id: DocumentId;
|
id: DocumentId;
|
||||||
campaign: Campaign;
|
campaign: Campaign;
|
||||||
data: {};
|
data: {};
|
||||||
@@ -35,6 +37,12 @@ export type Secret = Document &
|
|||||||
"secret",
|
"secret",
|
||||||
{
|
{
|
||||||
text: string;
|
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 }) => {
|
loader: async ({ params }) => {
|
||||||
const doc = await pb.collection("documents").getOne(params.documentId);
|
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,
|
component: RouteComponent,
|
||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const { document } = Route.useLoaderData();
|
const { document, secrets } = Route.useLoaderData();
|
||||||
const strongStart = document?.data?.session?.strongStart || "";
|
const strongStart = document?.data?.session?.strongStart || "";
|
||||||
|
|
||||||
async function handleSaveStrongStart(newValue: string) {
|
async function handleSaveStrongStart(newValue: string) {
|
||||||
// Update the document in Pocketbase
|
|
||||||
await pb.collection("documents").update(document.id, {
|
await pb.collection("documents").update(document.id, {
|
||||||
data: {
|
data: {
|
||||||
...document.data,
|
...document.data,
|
||||||
@@ -38,6 +50,18 @@ function RouteComponent() {
|
|||||||
placeholder="Enter a strong start for this session..."
|
placeholder="Enter a strong start for this session..."
|
||||||
aria-label="Strong Start"
|
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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user