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

View file

@ -1,27 +1,38 @@
import React, {useState} from 'react';
import React, {useReducer} from 'react';
import Maze from "./Maze";
import InputForm from "./InputForm";
import reduce from "./reducer";
import MessageBanner from "./MessageBanner";
export default function App() {
const [maze, setMaze] = useState({});
const [showSolution, setShowSolution] = useState(false);
const hasValidMaze = !!maze.width &&
!!maze.height &&
!!maze.id &&
!!maze.grid;
const [state, dispatch] = useReducer(reduce, {
maze: null,
loading: false,
errorMessage: null,
showSolution: false,
userPath: []
},
undefined);
const hasValidMaze = !!state.maze;
return (
<>
<InputForm handleResult={setMaze}/>
<MessageBanner state={state}
dispatch={dispatch}/>
<InputForm state={state}
dispatch={dispatch}/>
{hasValidMaze &&
<>
<h1>The Maze ({maze.width}x{maze.height}, ID: {maze.id})</h1>
<h1>The Maze ({state.maze.width}x{state.maze.height}, ID: {state.maze.id})</h1>
<input type={"checkbox"}
onChange={(e) => {
setShowSolution(e.target.checked);
dispatch({
type: 'toggled_show_solution',
value: e.target.checked
});
}}
id={"showSolution"}/><label htmlFor="showSolution">Show Solution</label>
<Maze labyrinth={maze}
showSolution={showSolution}/>
<Maze state={state}
dispatch={dispatch}/>
</>
}
</>