Completes the three-panel layout
This commit is contained in:
@@ -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",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user