refactor to use redux WIP

just pushing to save data
This commit is contained in:
2024-04-16 22:05:51 +02:00
parent 7f03bf900f
commit 69daf8ccae
26 changed files with 434 additions and 368 deletions
+13 -1
View File
@@ -12,6 +12,7 @@ import store, {AppDispatch, RootState} from './store'
import { Provider } from "react-redux"
import { useSelector, useDispatch } from 'react-redux'
import {load, setUser, unsetUser, userSelector} from './shared/domain-models/userSlice'
import {setCharacter} from "./second-edition/domain-models/characterSlice";
function Router(props: {faro?: Faro}) {
const dispatch = useDispatch.withTypes<AppDispatch>()()
@@ -79,7 +80,18 @@ function Router(props: {faro?: Faro}) {
{
path: "/2e/karakter/:id",
element: <CreateCharacter2E faro={props.faro}/>,
loader: args => fetch(`${window.location.origin}/api/Character2E/${args.params.id}`),
loader: async args => {
const response = await fetch(`${window.location.origin}/api/Character2E/${args.params.id}`)
if (response.ok) {
const loaded2Echaracter = await response.json()
dispatch(setCharacter(loaded2Echaracter))
return loaded2Echaracter;
}
return {
isPublic: false,
error: response.statusText,
};
},
ErrorBoundary: ErrorBoundary,
},
]);