Cleanup
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { useDocument } from "@/context/document/hooks";
|
||||
import { displayName, relationshipsForDocument } from "@/lib/relationships";
|
||||
import { RelationshipType, type DocumentId } from "@/lib/types";
|
||||
import { Route as CampaignRoute } from "@/routes/_app/_authenticated/campaigns.$campaignId";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import _ from "lodash";
|
||||
import { Loader } from "../Loader";
|
||||
|
||||
@@ -70,7 +70,7 @@ export const TreasureToggleRow = ({
|
||||
disabled={loading}
|
||||
/>
|
||||
<Link
|
||||
to="/document/$documentId"
|
||||
to="/document/$documentId/$"
|
||||
params={{ documentId: treasure.id }}
|
||||
className="text-lg !no-underline text-slate-100 hover:underline hover:text-violet-400"
|
||||
>
|
||||
|
||||
@@ -51,46 +51,54 @@ const simpleFields = <D extends DocumentType>(
|
||||
export function getFieldsForType<D extends DocumentType>(
|
||||
docType: D,
|
||||
): DocumentField<D, FieldType>[] {
|
||||
// Explicit casts are required because the getter function puts the type D in the parameters position and thus the specialized getter is not valid in the case of the more general document type.
|
||||
// While the switch correctly sees that D is now "front", the _type_ could be a union and thus the getter needs to be able to accept any of them.
|
||||
// I know this will only ever be called in the context of one value, but this is clearly abusing the type system.
|
||||
// TODO: Fix the types
|
||||
switch (docType) {
|
||||
case "front":
|
||||
return simpleFields<"front">({
|
||||
Name: ["name", "shortText"],
|
||||
Description: ["description", "longText"],
|
||||
Resolved: ["resolved", "toggle"],
|
||||
});
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "location":
|
||||
return [
|
||||
simpleField("Name", "name", "shortText"),
|
||||
simpleField("Description", "description", "longText"),
|
||||
];
|
||||
return simpleFields<"location">({
|
||||
Name: ["name", "shortText"],
|
||||
Description: ["description", "longText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "monster":
|
||||
return [simpleField("Name", "name", "shortText")];
|
||||
return simpleFields<"monster">({
|
||||
Name: ["name", "shortText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "npc":
|
||||
return [
|
||||
simpleField("Name", "name", "shortText"),
|
||||
simpleField("Description", "description", "longText"),
|
||||
];
|
||||
return simpleFields<"npc">({
|
||||
Name: ["name", "shortText"],
|
||||
Description: ["description", "longText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "scene":
|
||||
return [simpleField("Text", "text", "longText")];
|
||||
return simpleFields<"scene">({
|
||||
Text: ["text", "longText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "secret":
|
||||
return [
|
||||
simpleField("Discovered", "discovered", "toggle"),
|
||||
simpleField("Text", "text", "shortText"),
|
||||
];
|
||||
return simpleFields<"secret">({
|
||||
Discovered: ["discovered", "toggle"],
|
||||
Text: ["text", "shortText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "session":
|
||||
return [
|
||||
simpleField("Name", "name", "shortText"),
|
||||
simpleField("Strong Start", "strongStart", "longText"),
|
||||
];
|
||||
return simpleFields<"session">({
|
||||
Name: ["name", "shortText"],
|
||||
"Strong Start": ["strongStart", "longText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "thread":
|
||||
return [
|
||||
simpleField("Resolved", "resolved", "toggle"),
|
||||
simpleField("Text", "text", "shortText"),
|
||||
];
|
||||
return simpleFields<"thread">({
|
||||
Resolved: ["resolved", "toggle"],
|
||||
Text: ["text", "shortText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
case "treasure":
|
||||
return [
|
||||
simpleField("Discovered", "discovered", "toggle"),
|
||||
simpleField("Text", "text", "shortText"),
|
||||
];
|
||||
return simpleFields<"treasure">({
|
||||
Discovered: ["discovered", "toggle"],
|
||||
Text: ["text", "shortText"],
|
||||
}) as unknown as DocumentField<D, FieldType>[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
getDocumentType,
|
||||
type DocumentType,
|
||||
RelationshipType,
|
||||
type AnyDocument,
|
||||
} from "./types";
|
||||
import { getDocumentType, RelationshipType, type AnyDocument } from "./types";
|
||||
|
||||
export function displayName(relationshipType: RelationshipType) {
|
||||
return relationshipType.charAt(0).toUpperCase() + relationshipType.slice(1);
|
||||
|
||||
@@ -5,9 +5,9 @@ import { Loader } from "@/components/Loader";
|
||||
import { DocumentLoader } from "@/context/document/DocumentLoader";
|
||||
import { useDocument } from "@/context/document/hooks";
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
import type { Campaign, DocumentId, Relationship, Session } from "@/lib/types";
|
||||
import type { Campaign, DocumentId } from "@/lib/types";
|
||||
import { createFileRoute, Link } from "@tanstack/react-router";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
const CampaignTabs = {
|
||||
|
||||
@@ -43,6 +43,7 @@ function RouteComponent() {
|
||||
to="/campaigns/$campaignId"
|
||||
params={{ campaignId: c.id }}
|
||||
className="block px-4 py-2 rounded bg-slate-800 hover:bg-violet-700 text-slate-100 transition-colors"
|
||||
search={{ tab: "sessions" }}
|
||||
>
|
||||
{c.name}
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user