Skip to content

Commit

Permalink
Placeholder for select
Browse files Browse the repository at this point in the history
  • Loading branch information
sadanandpai committed Mar 16, 2024
1 parent 8796c32 commit a2452cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/apps/path-finder/components/controller/execution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { searchPath } from '../../store/search-thunk';

function Execution() {
const dispatch = useAppDispatch();
const [pathFinder, setPathFinder] = useState<string>();
const [pathFinder, setPathFinder] = useState('');
const [speed, setSpeed] = useState([...searchSpeeds.values()][1]);
const entry = useAppSelector((state) => state.pathFinder.entry);
const exit = useAppSelector((state) => state.pathFinder.exit);
Expand Down Expand Up @@ -68,6 +68,9 @@ function Execution() {
onChange={handleChange}
disabled={disabled}
>
<option value="" disabled>
Select path finder
</option>
{[...pathFinders.entries()].map(([key, { name }]) => (
<option key={key} value={key}>
{name}
Expand Down
13 changes: 10 additions & 3 deletions src/apps/path-finder/components/controller/operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { mazeSpeeds } from '../../config';

function Operations() {
const dispatch = useAppDispatch();
const [maze, setMaze] = useState<string>('');
const [speed, setSpeed] = useState([...mazeSpeeds.values()][1]);
const [maze, setMaze] = useState([...mazeGenerators.keys()][0]);
const status = useAppSelector((state) => state.pathFinder.status);
const mazeAlgo = mazeGenerators.get(maze);
const mazeAlgo = maze ? mazeGenerators.get(maze) : null;
const disabled = status === Status.Generating || status === Status.Searching;

function mazeClickHandler(algo = mazeAlgo) {
Expand All @@ -24,6 +24,10 @@ function Operations() {

function handleChange(e: React.ChangeEvent<HTMLSelectElement>) {
const algo = e.target.value;
if (!algo) {
return;
}

setMaze(algo);
mazeClickHandler(mazeGenerators.get(algo));
}
Expand All @@ -38,6 +42,9 @@ function Operations() {
className={classes.mazeSelector}
disabled={disabled}
>
<option value="" disabled>
Select Maze Algo
</option>
{[...mazeGenerators.entries()].map(([key, { name }]) => (
<option key={key} value={key}>
{name}
Expand Down Expand Up @@ -65,7 +72,7 @@ function Operations() {
data-testid="generate-maze"
onClick={() => mazeClickHandler()}
data-tooltip="Play"
disabled={disabled}
disabled={disabled || maze === ''}
>
<Play size={20} />
</button>
Expand Down

0 comments on commit a2452cf

Please sign in to comment.