update react

This commit is contained in:
Manuel Friedli 2024-12-26 17:38:31 +01:00
parent 804ce323bf
commit 7d4f1151fa
Signed by: manuel
GPG key ID: 41D08ABA75634DA1
40 changed files with 3573 additions and 14078 deletions

58
src/app/state/reducer.ts Normal file
View file

@ -0,0 +1,58 @@
import handleUserClicked from "./userpathhandler.ts";
import {State} from "./state";
import {
Action,
ID_ACTION_CLICKED_CELL,
ID_ACTION_CLOSED_MESSAGE_BANNER,
ID_ACTION_LOADED_MAZE,
ID_ACTION_LOADING_FAILED,
ID_ACTION_STARTED_LOADING,
ID_ACTION_TOGGLED_SHOW_SOLUTION
} from "./action.ts";
export default function reduce(state: State, action: Action): State {
switch (action.type) {
case ID_ACTION_STARTED_LOADING: {
return {
...state,
maze: null,
loading: true,
errorMessage: null
}
}
case ID_ACTION_LOADED_MAZE: {
return {
...state,
loading: false,
maze: action.maze,
userPath: []
}
}
case ID_ACTION_LOADING_FAILED: {
return {
...state,
loading: false,
errorMessage: `Failed to load maze. Reason: ${action.reason}`
}
}
case ID_ACTION_TOGGLED_SHOW_SOLUTION: {
return {
...state,
showSolution: action.value
}
}
case ID_ACTION_CLOSED_MESSAGE_BANNER: {
return {
...state,
errorMessage: null
}
}
case ID_ACTION_CLICKED_CELL: {
// There's so much logic involved, externalize that into its own file.
return handleUserClicked(state, action.x, action.y);
}
default: {
throw new Error(`Unknown action: ${action.type}`);
}
}
}