Cleanup
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { useDocument } from "@/context/document/hooks";
|
import { useDocument } from "@/context/document/hooks";
|
||||||
import { displayName, relationshipsForDocument } from "@/lib/relationships";
|
import { displayName, relationshipsForDocument } from "@/lib/relationships";
|
||||||
import { RelationshipType, type DocumentId } from "@/lib/types";
|
import { RelationshipType, type DocumentId } from "@/lib/types";
|
||||||
import { Route as CampaignRoute } from "@/routes/_app/_authenticated/campaigns.$campaignId";
|
|
||||||
import { Link } from "@tanstack/react-router";
|
import { Link } from "@tanstack/react-router";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Loader } from "../Loader";
|
import { Loader } from "../Loader";
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export const TreasureToggleRow = ({
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
to="/document/$documentId"
|
to="/document/$documentId/$"
|
||||||
params={{ documentId: treasure.id }}
|
params={{ documentId: treasure.id }}
|
||||||
className="text-lg !no-underline text-slate-100 hover:underline hover:text-violet-400"
|
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>(
|
export function getFieldsForType<D extends DocumentType>(
|
||||||
docType: D,
|
docType: D,
|
||||||
): DocumentField<D, FieldType>[] {
|
): 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) {
|
switch (docType) {
|
||||||
case "front":
|
case "front":
|
||||||
return simpleFields<"front">({
|
return simpleFields<"front">({
|
||||||
Name: ["name", "shortText"],
|
Name: ["name", "shortText"],
|
||||||
Description: ["description", "longText"],
|
Description: ["description", "longText"],
|
||||||
Resolved: ["resolved", "toggle"],
|
Resolved: ["resolved", "toggle"],
|
||||||
});
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "location":
|
case "location":
|
||||||
return [
|
return simpleFields<"location">({
|
||||||
simpleField("Name", "name", "shortText"),
|
Name: ["name", "shortText"],
|
||||||
simpleField("Description", "description", "longText"),
|
Description: ["description", "longText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "monster":
|
case "monster":
|
||||||
return [simpleField("Name", "name", "shortText")];
|
return simpleFields<"monster">({
|
||||||
|
Name: ["name", "shortText"],
|
||||||
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "npc":
|
case "npc":
|
||||||
return [
|
return simpleFields<"npc">({
|
||||||
simpleField("Name", "name", "shortText"),
|
Name: ["name", "shortText"],
|
||||||
simpleField("Description", "description", "longText"),
|
Description: ["description", "longText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "scene":
|
case "scene":
|
||||||
return [simpleField("Text", "text", "longText")];
|
return simpleFields<"scene">({
|
||||||
|
Text: ["text", "longText"],
|
||||||
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "secret":
|
case "secret":
|
||||||
return [
|
return simpleFields<"secret">({
|
||||||
simpleField("Discovered", "discovered", "toggle"),
|
Discovered: ["discovered", "toggle"],
|
||||||
simpleField("Text", "text", "shortText"),
|
Text: ["text", "shortText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "session":
|
case "session":
|
||||||
return [
|
return simpleFields<"session">({
|
||||||
simpleField("Name", "name", "shortText"),
|
Name: ["name", "shortText"],
|
||||||
simpleField("Strong Start", "strongStart", "longText"),
|
"Strong Start": ["strongStart", "longText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "thread":
|
case "thread":
|
||||||
return [
|
return simpleFields<"thread">({
|
||||||
simpleField("Resolved", "resolved", "toggle"),
|
Resolved: ["resolved", "toggle"],
|
||||||
simpleField("Text", "text", "shortText"),
|
Text: ["text", "shortText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
case "treasure":
|
case "treasure":
|
||||||
return [
|
return simpleFields<"treasure">({
|
||||||
simpleField("Discovered", "discovered", "toggle"),
|
Discovered: ["discovered", "toggle"],
|
||||||
simpleField("Text", "text", "shortText"),
|
Text: ["text", "shortText"],
|
||||||
];
|
}) as unknown as DocumentField<D, FieldType>[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import {
|
import { getDocumentType, RelationshipType, type AnyDocument } from "./types";
|
||||||
getDocumentType,
|
|
||||||
type DocumentType,
|
|
||||||
RelationshipType,
|
|
||||||
type AnyDocument,
|
|
||||||
} from "./types";
|
|
||||||
|
|
||||||
export function displayName(relationshipType: RelationshipType) {
|
export function displayName(relationshipType: RelationshipType) {
|
||||||
return relationshipType.charAt(0).toUpperCase() + relationshipType.slice(1);
|
return relationshipType.charAt(0).toUpperCase() + relationshipType.slice(1);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { Loader } from "@/components/Loader";
|
|||||||
import { DocumentLoader } from "@/context/document/DocumentLoader";
|
import { DocumentLoader } from "@/context/document/DocumentLoader";
|
||||||
import { useDocument } from "@/context/document/hooks";
|
import { useDocument } from "@/context/document/hooks";
|
||||||
import { pb } from "@/lib/pocketbase";
|
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 { createFileRoute, Link } from "@tanstack/react-router";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const CampaignTabs = {
|
const CampaignTabs = {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ function RouteComponent() {
|
|||||||
to="/campaigns/$campaignId"
|
to="/campaigns/$campaignId"
|
||||||
params={{ campaignId: c.id }}
|
params={{ campaignId: c.id }}
|
||||||
className="block px-4 py-2 rounded bg-slate-800 hover:bg-violet-700 text-slate-100 transition-colors"
|
className="block px-4 py-2 rounded bg-slate-800 hover:bg-violet-700 text-slate-100 transition-colors"
|
||||||
|
search={{ tab: "sessions" }}
|
||||||
>
|
>
|
||||||
{c.name}
|
{c.name}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user