Forms now update documents directly.

This commit is contained in:
2025-07-02 17:36:45 -07:00
parent f27432ef05
commit db4ce36c27
17 changed files with 120 additions and 228 deletions

View File

@@ -1,4 +1,5 @@
import { AutoSaveTextarea } from "@/components/AutoSaveTextarea";
import { useDocument } from "@/context/document/DocumentContext";
import { pb } from "@/lib/pocketbase";
import type { Npc } from "@/lib/types";
@@ -6,22 +7,25 @@ import type { Npc } from "@/lib/types";
* Renders an editable npc form
*/
export const NpcEditForm = ({ npc }: { npc: Npc }) => {
const { dispatch } = useDocument();
async function saveNpcName(name: string) {
await pb.collection("documents").update(npc.id, {
const updated: Npc = await pb.collection("documents").update(npc.id, {
data: {
...npc.data,
name,
},
});
dispatch({ type: "setDocument", doc: updated });
}
async function saveNpcDescription(description: string) {
await pb.collection("documents").update(npc.id, {
const updated: Npc = await pb.collection("documents").update(npc.id, {
data: {
...npc.data,
description,
},
});
dispatch({ type: "setDocument", doc: updated });
}
return (