diff --git a/src/components/RelationshipList.tsx b/src/components/RelationshipList.tsx
index d168953..e86c3e2 100644
--- a/src/components/RelationshipList.tsx
+++ b/src/components/RelationshipList.tsx
@@ -3,7 +3,7 @@ import { pb } from "@/lib/pocketbase";
import type { Document, RelationshipType } from "@/lib/types";
import { useState } from "react";
import { Loader } from "./Loader";
-import { NewRelatedDocumentForm } from "./documents/NewRelatedDocumentForm";
+import { DocumentForm } from "./documents/DocumentForm";
import { DocumentRow } from "./documents/DocumentRow";
interface RelationshipListProps {
@@ -68,7 +68,7 @@ export function RelationshipList({
error={error}
renderRow={(document) => }
newItemForm={(onSubmit) => (
- {
diff --git a/src/components/documents/NewRelatedDocumentForm.tsx b/src/components/documents/DocumentForm.tsx
similarity index 83%
rename from src/components/documents/NewRelatedDocumentForm.tsx
rename to src/components/documents/DocumentForm.tsx
index 3d7d8d0..d700acb 100644
--- a/src/components/documents/NewRelatedDocumentForm.tsx
+++ b/src/components/documents/DocumentForm.tsx
@@ -7,13 +7,13 @@ import { SecretForm } from "./secret/SecretForm";
import { TreasureForm } from "./treasure/TreasureForm";
function assertUnreachable(_x: never): never {
- throw new Error("NewRelatedDocumentForm switch is not exhaustive");
+ throw new Error("DocumentForm switch is not exhaustive");
}
/**
* Renders a form for any document type depending on the relationship.
*/
-export const NewRelatedDocumentForm = ({
+export const DocumentForm = ({
campaignId,
relationshipType,
onCreate,
@@ -24,27 +24,19 @@ export const NewRelatedDocumentForm = ({
}) => {
switch (relationshipType) {
case RelationshipType.Locations:
- return (
-
- );
+ return ;
case RelationshipType.Monsters:
return ;
case RelationshipType.Npcs:
return ;
case RelationshipType.Secrets:
return ;
+ case RelationshipType.DiscoveredIn:
+ return "Form not supported here";
case RelationshipType.Treasures:
return ;
case RelationshipType.Scenes:
return ;
- case RelationshipType.DiscoveredIn:
- return "Form not supported here";
}
return assertUnreachable(relationshipType);
diff --git a/src/components/documents/Forms.ts b/src/components/documents/Forms.ts
deleted file mode 100644
index f451fd5..0000000
--- a/src/components/documents/Forms.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import type { CampaignId, Document } from "@/lib/types";
-
-export type FormTarget =
- | {
- type: "new";
- campaignId: CampaignId;
- document?: undefined;
- }
- | {
- type: "existing";
- document: T;
- };
diff --git a/src/components/documents/location/LocationForm.tsx b/src/components/documents/location/LocationForm.tsx
index c6a1dc4..7eed94b 100644
--- a/src/components/documents/location/LocationForm.tsx
+++ b/src/components/documents/location/LocationForm.tsx
@@ -1,22 +1,19 @@
import { useState } from "react";
-import type { Location } from "@/lib/types";
+import type { CampaignId, Location } from "@/lib/types";
import { pb } from "@/lib/pocketbase";
-import type { FormTarget } from "../Forms";
/**
* Renders a form to add a new location. Calls onCreate with the new location document.
*/
export const LocationForm = ({
- target,
- onSubmit,
+ campaign,
+ onCreate,
}: {
- target: FormTarget;
- onSubmit: (location: Location) => Promise;
+ campaign: CampaignId;
+ onCreate: (location: Location) => Promise;
}) => {
- const [name, setName] = useState(target.document?.data.location.name ?? "");
- const [description, setDescription] = useState(
- target.document?.data.location.description ?? "",
- );
+ const [name, setName] = useState("");
+ const [description, setDescription] = useState("");
const [adding, setAdding] = useState(false);
const [error, setError] = useState(null);
@@ -26,32 +23,18 @@ export const LocationForm = ({
setAdding(true);
setError(null);
try {
- if (target.type === "new") {
- const locationDoc: Location = await pb.collection("documents").create({
- campaign: target.campaignId,
- data: {
- location: {
- name,
- description,
- },
+ const locationDoc: Location = await pb.collection("documents").create({
+ campaign,
+ data: {
+ location: {
+ name,
+ description,
},
- });
- setName("");
- setDescription("");
- await onSubmit(locationDoc);
- } else {
- const locationDoc: Location = await pb
- .collection("documents")
- .update(target.document.id, {
- data: {
- location: {
- name,
- description,
- },
- },
- });
- await onSubmit(locationDoc);
- }
+ },
+ });
+ setName("");
+ setDescription("");
+ await onCreate(locationDoc);
} catch (e: any) {
setError(e?.message || "Failed to add location.");
} finally {
@@ -64,7 +47,7 @@ export const LocationForm = ({
className="flex items-left flex-col gap-2 mt-4"
onSubmit={handleSubmit}
>
- Create ne w location
+ Create new location