diff --git a/actions/Schemas/index.ts b/actions/Schemas/index.ts index 6118710..4f6f9f2 100644 --- a/actions/Schemas/index.ts +++ b/actions/Schemas/index.ts @@ -22,6 +22,7 @@ export const saveSchemaDb = async (s: Schema, version: number) => { }, }, authorId: sesh.user.id, + gameSystemId: s.gameSystemId, id: undefined, }, update: { diff --git a/components/Poppables/help.tsx b/components/Poppables/help.tsx index c667346..7e81b43 100644 --- a/components/Poppables/help.tsx +++ b/components/Poppables/help.tsx @@ -1,6 +1,6 @@ import { FC, PropsWithChildren } from "react"; import { Poppable } from "@/lib/poppables/components/poppable"; -import { Icon } from "@/components/Icon"; +import { QuestionMarkCircleIcon } from "@heroicons/react/24/solid"; export const HelpPopper: FC = ({ children }) => { return ( @@ -9,7 +9,7 @@ export const HelpPopper: FC = ({ children }) => { preferredAlign="centered" preferredEdge="bottom" > - + ); }; diff --git a/components/schema/field-editor.tsx b/components/schema/field-editor.tsx index b1d163d..b533a68 100644 --- a/components/schema/field-editor.tsx +++ b/components/schema/field-editor.tsx @@ -2,13 +2,14 @@ import { FC, useCallback, useEffect, useState } from "react"; import { useObjectStateWrapper } from "../../hooks/useObjectState"; import { ValueField } from "./value-field"; import { HelpPopper } from "../Poppables/help"; -import { Icon } from "../Icon"; import { RESERVED_FIELDS } from "../../constants/ReservedFields"; import { fieldTypeOptions, FieldTypes, fieldTypesWithValues, } from "./fieldtypes"; +import { TrashIcon } from "@heroicons/react/24/solid"; +import { FieldType } from "@/types"; interface IProps { update: (arg: FieldType) => void; @@ -17,9 +18,12 @@ interface IProps { deleteField: (arg: string) => void; } -export const FieldEditor: FC = ( - { update, field, fieldName, deleteField }, -) => { +export const FieldEditor: FC = ({ + update, + field, + fieldName, + deleteField, +}) => { const { bindProperty, bindPropertyCheck } = useObjectStateWrapper( field, (e) => update(typeof e === "function" ? e(field) : e), @@ -83,9 +87,8 @@ export const FieldEditor: FC = ( )}

@@ -108,7 +111,11 @@ export const FieldEditor: FC = (

@@ -122,11 +129,7 @@ export const FieldEditor: FC = ( className="no-default self-end ml-auto" onClick={() => deleteField(fieldName)} > - - + )} diff --git a/components/schema/index.tsx b/components/schema/index.tsx index 8a62c71..fe05c2b 100644 --- a/components/schema/index.tsx +++ b/components/schema/index.tsx @@ -15,6 +15,8 @@ import { findSchema, saveSchemaDb } from "@/actions/Schemas/index"; import { useToast } from "../toast"; import { useAtom } from "jotai"; import { Schema, TypeType } from "@/types"; +import { TrashIcon } from "@heroicons/react/24/solid"; +import { PencilSquareIcon } from "@heroicons/react/24/solid"; export const SchemaBuilder: FC = () => { const [schema, setSchema] = useAtom(SchemaEditAtom); @@ -184,20 +186,14 @@ export const SchemaBuilder: FC = () => { className="no-default" onClick={() => selectTypeForEdit(t)} > - + diff --git a/components/schema/schema-viewer.tsx b/components/schema/schema-viewer.tsx index cc62027..951910c 100644 --- a/components/schema/schema-viewer.tsx +++ b/components/schema/schema-viewer.tsx @@ -34,10 +34,10 @@ export const SchemaViewer: FC = ({ schema, onTypeClick }) => {


Templates

    - {Object.entries(schema.schema).map(([templateKey, template]) => ( + {Object.entries(schema.fields).map(([templateKey, template]) => (
  • {templateKey}

    -

    {template.type}

    +

    Type: {template}

  • ))}
diff --git a/components/schema/template-editor.tsx b/components/schema/template-editor.tsx index 315e92d..99516a7 100644 --- a/components/schema/template-editor.tsx +++ b/components/schema/template-editor.tsx @@ -6,6 +6,7 @@ import { FieldTypes } from "./fieldtypes"; import { useAtom } from "jotai"; import { useInput } from "@/hooks/useInput"; import { Schema } from "@/types"; +import { TrashIcon } from "@heroicons/react/24/solid"; interface IProps { templateKey: string; @@ -19,19 +20,11 @@ export const TemplateEditor: FC = ({ fieldType, }) => { const [schema, setSchema] = useAtom(SchemaEditAtom); - // const updateTemplate = useCallback( - // (t: FieldTypes | ((arg: FieldTypes) => FieldTypes)) => { - // update(templateKey, typeof t === "function" ? t(template) : t); - // }, - // [templateKey, update, template], - // ); - - // const { bindProperty } = useObjectStateWrapper(template, updateTemplate); const { bind: bindFieldType, value } = useInput(fieldType); useEffect(() => { update(templateKey, value); - }); + }, []); const deleteField = useCallback(() => { setSchema((s: Schema) => { @@ -70,10 +63,7 @@ export const TemplateEditor: FC = ({ diff --git a/components/schema/type-editor.tsx b/components/schema/type-editor.tsx index 03a70c8..f83e288 100644 --- a/components/schema/type-editor.tsx +++ b/components/schema/type-editor.tsx @@ -9,6 +9,7 @@ import { useObjectState } from "../../hooks/useObjectState"; import { useInput } from "../../hooks/useInput"; import { FieldEditor } from "./field-editor"; import { FieldTypes } from "./fieldtypes"; +import { FieldType, TypeType } from "@/types"; interface IProps { name: string; @@ -18,9 +19,11 @@ interface IProps { const constantProperties = ["metadata"]; -export const TypeEditor: FC> = ( - { saveType, name, type: passedType }, -) => { +export const TypeEditor: FC> = ({ + saveType, + name, + type: passedType, +}) => { const { update: updateType, reset: resetType, @@ -39,19 +42,22 @@ export const TypeEditor: FC> = ( resetType(); }; - const addField = useCallback((e: FormEvent) => { - e.preventDefault(); - updateType({ - [propertyName]: { - type: FieldTypes.number, - value: "", - isConstant: false, - limit: 1, - minimum: 1, - }, - }); - resetPropertyName(); - }, [propertyName, updateType, resetPropertyName]); + const addField = useCallback( + (e: FormEvent) => { + e.preventDefault(); + updateType({ + [propertyName]: { + type: FieldTypes.number, + value: "", + isConstant: false, + limit: 1, + minimum: 1, + }, + }); + resetPropertyName(); + }, + [propertyName, updateType, resetPropertyName], + ); const updateField = useCallback( (k: keyof typeof type) => (field: FieldType) => { @@ -64,13 +70,16 @@ export const TypeEditor: FC> = ( passedType && setType(passedType); }, [passedType, setType]); - const deleteField = useCallback((name: string) => { - setType((t) => { - const fields = { ...t }; - delete fields[name]; - return fields; - }); - }, [setType]); + const deleteField = useCallback( + (name: string) => { + setType((t) => { + const fields = { ...t }; + delete fields[name]; + return fields; + }); + }, + [setType], + ); return (
@@ -82,17 +91,18 @@ export const TypeEditor: FC> = (
    - {Object.entries(type).reverse().filter(([k]) => - !constantProperties.includes(k) - ).map(([key, value]) => ( - - ))} + {Object.entries(type) + .reverse() + .filter(([k]) => !constantProperties.includes(k)) + .map(([key, value]) => ( + + ))}