Moves editing into forms. Every doc has a page now. BUG: state not refreshed after mutation

This commit is contained in:
2025-06-13 16:58:26 -07:00
parent 293e1f9f62
commit ad8fb07c69
14 changed files with 313 additions and 59 deletions

View File

@@ -0,0 +1,46 @@
import { AutoSaveTextarea } from "@/components/AutoSaveTextarea";
import { pb } from "@/lib/pocketbase";
import type { Npc } from "@/lib/types";
/**
* Renders an editable npc form
*/
export const NpcEditForm = ({ npc }: { npc: Npc }) => {
async function saveNpcName(name: string) {
await pb.collection("documents").update(npc.id, {
data: {
...npc.data,
npc: {
...npc.data.npc,
name,
},
},
});
}
async function saveNpcDescription(description: string) {
await pb.collection("documents").update(npc.id, {
data: {
...npc.data,
npc: {
...npc.data.npc,
description,
},
},
});
}
return (
<div className="">
<AutoSaveTextarea
multiline={false}
value={npc.data.npc.name}
onSave={saveNpcName}
/>
<AutoSaveTextarea
value={npc.data.npc.description}
onSave={saveNpcDescription}
/>
</div>
);
};