diff --git a/project-warstone/package.json b/project-warstone/package.json index c78782c..9f9289e 100644 --- a/project-warstone/package.json +++ b/project-warstone/package.json @@ -12,12 +12,14 @@ }, "dependencies": { "@types/react-router-dom": "^5.3.3", + "@types/recoilize": "^0.8.0", "autoprefixer": "^10.4.14", "postcss": "^8.4.24", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.12.0", "recoil": "^0.7.7", + "recoilize": "^3.2.0", "tailwindcss": "^3.3.2", "vite-plugin-svgr": "^3.2.0" }, diff --git a/project-warstone/src/App.tsx b/project-warstone/src/App.tsx index 91a0005..2bcdc80 100644 --- a/project-warstone/src/App.tsx +++ b/project-warstone/src/App.tsx @@ -1,10 +1,14 @@ import { RecoilRoot } from 'recoil' import { SchemaBuilder } from './components/SchemaBuilder' +import { GameSystemEditor } from './components/GameSystemEditor' +import RecoilizeDebugger from 'recoilize'; function App() { return ( - + + {/* */} + ) } diff --git a/project-warstone/src/components/GameSystemEditor/index.tsx b/project-warstone/src/components/GameSystemEditor/index.tsx new file mode 100644 index 0000000..995f57d --- /dev/null +++ b/project-warstone/src/components/GameSystemEditor/index.tsx @@ -0,0 +1,87 @@ +import { FC, useCallback, useEffect, useState } from 'react' +import { GameSystem } from '../../types/gameSystem'; +import { useObjectState } from '../../hooks/useObjectState'; +import { GameSystemsService } from '../../services/game-systems'; + +export const GameSystemEditor: FC = () => { + const { state: gameSystem, update: updateGameSystem, bindProperty: bindGameSystemProperty, setState: setGameSystem } = useObjectState({ + id: '', + schema: { + id: '', + name: '', + templates: {}, + types: {} + }, + schemaId: '286f4c18-d280-444b-8d7e-9a3dd09f64ef', + name: 'Asshammer 40x a day', + accolades: [], + }); + const [schemas, setSchemas] = useState<{ name: string, id: string }[]>([]); + + const [lastSaved, setLastSaved] = useState(gameSystem); + + const fetchSchema = useCallback(async (id: string) => { + const res = await GameSystemsService.getSchema(id); + + if (res.status !== 200) return; + const schema = await res.json() + + updateGameSystem({ + schema + }); + }, [updateGameSystem]) + + useEffect(() => { + if (gameSystem.schemaId === gameSystem.schema.id) return; + fetchSchema(gameSystem.schemaId); + }, [fetchSchema, gameSystem.schema.id, gameSystem.schemaId]); + + useEffect(() => { + GameSystemsService.getSchemaList() + .then(res => res.json()) + .then(schemas => setSchemas(schemas)); + }, []); + + const saveGameSystem = useCallback(() => { + GameSystemsService.saveGameSystem(gameSystem); + setLastSaved(gameSystem); + }, [gameSystem]) + + const fetchGameSystem = useCallback(async () => { + const res = await GameSystemsService.getGameSystem(''); + const gs = await res.json(); + setGameSystem(gs); + setLastSaved(gs); + }, [setGameSystem]); + + useEffect(() => { + fetchGameSystem() + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( +
+
+ + + +
+
+

Accolades

+
+ {gameSystem.accolades.map(a => ( +
+

{a.name}

+

{a.description}

+
+ ))} +
+
+
+ ) +} \ No newline at end of file diff --git a/project-warstone/src/components/SchemaBuilder/field-type-input.tsx b/project-warstone/src/components/SchemaBuilder/field-type-input.tsx index 05a7854..9a9004d 100644 --- a/project-warstone/src/components/SchemaBuilder/field-type-input.tsx +++ b/project-warstone/src/components/SchemaBuilder/field-type-input.tsx @@ -9,7 +9,7 @@ interface IProps { } export const FieldTypeInput: FCC = ({ bind }) => { - const Schema = useRecoilValue(SchemaEditAtom); + const schema = useRecoilValue(SchemaEditAtom); return (