Implemented a half-way okay-ish user interaction pattern: mouse drag.
This commit is contained in:
parent
0e5892147a
commit
8f64a65a2a
9 changed files with 233 additions and 72 deletions
48
src/reducer.js
Normal file
48
src/reducer.js
Normal 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}`);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue