Completes the three-panel layout

This commit is contained in:
2025-07-21 20:50:18 -07:00
parent 3390ecfb95
commit 8533f63a22
11 changed files with 184 additions and 74 deletions

View File

@@ -1,7 +1,7 @@
// TreasureRow.tsx
// Displays a single treasure with discovered checkbox and text.
import { pb } from "@/lib/pocketbase";
import type { Session, Treasure } from "@/lib/types";
import type { AnyDocument, Treasure } from "@/lib/types";
import { Link } from "@tanstack/react-router";
import { useState } from "react";
@@ -11,10 +11,10 @@ import { useState } from "react";
*/
export const TreasureToggleRow = ({
treasure,
session,
root,
}: {
treasure: Treasure;
session?: Session;
root?: AnyDocument;
}) => {
const [checked, setChecked] = useState(
!!(treasure.data as any)?.treasure?.discovered,
@@ -35,7 +35,7 @@ export const TreasureToggleRow = ({
},
},
});
if (session || !newChecked) {
if (root || !newChecked) {
// If the session exists or the element is being unchecked, remove any
// existing discoveredIn relationship
const rels = await pb.collection("relationships").getList(1, 1, {
@@ -45,11 +45,11 @@ export const TreasureToggleRow = ({
await pb.collection("relationships").delete(rels.items[0].id);
}
}
if (session) {
if (root) {
if (newChecked) {
await pb.collection("relationships").create({
primary: treasure.id,
secondary: [session.id],
secondary: [root.id],
type: "discoveredIn",
});
}