Implemented a half-way okay-ish user interaction pattern: mouse drag.

This commit is contained in:
Manuel Friedli 2023-04-17 01:19:42 +02:00
parent 0e5892147a
commit 8f64a65a2a
9 changed files with 233 additions and 72 deletions

48
src/reducer.js Normal file
View file

@ -0,0 +1,48 @@
import handleUserClicked from "./userpathhandler";
export default function reduce(state, action) {
switch (action.type) {
case 'started_loading': {
return {
...state,
maze: null,
loading: true,
errorMessage: null
}
}
case 'loaded_maze': {
return {
...state,
loading: false,
maze: action.maze,
userPath: []
}
}
case 'loading_failed': {
return {
...state,
loading: false,
errorMessage: `Failed to load maze. Reason: ${action.reason}`
}
}
case 'toggled_show_solution': {
return {
...state,
showSolution: action.value
}
}
case 'closed_message_banner': {
return {
...state,
errorMessage: null
}
}
case '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}`);
}
}
}