-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sadanand Pai
committed
Oct 2, 2023
1 parent
194e323
commit f1b8354
Showing
58 changed files
with
470 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": false, | ||
"arrowParens": "always", | ||
"proseWrap": "always", | ||
"htmlWhitespaceSensitivity": "css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/apps/sorting-visualizer/components/cell/swapping-cell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/apps/sorting-visualizer/components/controller/algo-selection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 31 additions & 75 deletions
106
src/apps/sorting-visualizer/components/controller/array-input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,49 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { | ||
setArray, | ||
setIsPlaying, | ||
setReset | ||
} from '@/apps/sorting-visualizer/store/sorting-visualizer.slice' | ||
import { useAppDispatch, useAppSelector } from '@/store/hooks' | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
convertArrayStringToArray, | ||
convertInputToArrayString, | ||
getRndmNumInRange, | ||
sortArray | ||
} from '@/apps/sorting-visualizer/helpers/array-helpers' | ||
|
||
import classes from './controls.module.scss' | ||
} from '@/apps/sorting-visualizer/helpers/array-helpers'; | ||
import { | ||
setArray, | ||
setIsPlaying, | ||
setReset, | ||
} from '@/apps/sorting-visualizer/store/sorting-visualizer.slice'; | ||
import { useAppDispatch, useAppSelector } from '@/store/hooks'; | ||
|
||
type SortFunction = () => void | ||
import NumberGenerator from './number-generator'; | ||
import classes from './controls.module.scss'; | ||
|
||
function ArrayInput () { | ||
const dispatch = useAppDispatch() | ||
const array = useAppSelector(state => state.sortViz.array) | ||
const [input, setInput] = useState(array.join(', ')) | ||
// const [sortingOptionsVisible, setSortingOptionsVisible] = useState(false) | ||
function ArrayInput() { | ||
const dispatch = useAppDispatch(); | ||
const array = useAppSelector((state) => state.sortViz.array); | ||
const [input, setInput] = useState(array.join(', ')); | ||
|
||
useEffect(() => { | ||
dispatch(setIsPlaying(false)) | ||
dispatch(setReset()) | ||
}, [array, dispatch]) | ||
|
||
const onRandomize = () => { | ||
const newInput = Array.from(new Array(getRndmNumInRange(10, 40)), () => | ||
getRndmNumInRange() | ||
) | ||
setInput(newInput.join(', ')) | ||
dispatch(setArray(newInput)) | ||
} | ||
|
||
const handleSortAscending = () => { | ||
const sortedAscending = sortArray(input, 'asc'); | ||
setInput(sortedAscending.join(', ')); | ||
dispatch(setArray(sortedAscending)); | ||
} | ||
|
||
const handleSortDescending = () => { | ||
const sortedDescending = sortArray(input, 'desc'); | ||
setInput(sortedDescending.join(', ')); | ||
dispatch(setArray(sortedDescending)); | ||
} | ||
|
||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const inputAsStr = convertInputToArrayString(e.target.value) | ||
setInput(inputAsStr) | ||
dispatch(setArray(convertArrayStringToArray(inputAsStr))) | ||
} | ||
|
||
const sortOptions: { [key: string]: SortFunction } = { | ||
ascending: handleSortAscending, | ||
descending: handleSortDescending | ||
} | ||
dispatch(setIsPlaying(false)); | ||
dispatch(setReset()); | ||
setInput(array.join(', ')); | ||
}, [array, dispatch]); | ||
|
||
const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const inputAsStr = convertInputToArrayString(e.target.value); | ||
setInput(inputAsStr); | ||
const inputAsArray = convertArrayStringToArray(inputAsStr); | ||
dispatch(setArray(inputAsArray)); | ||
}; | ||
|
||
return ( | ||
<div className={classes.numbers}> | ||
<button className={classes.rndmBtn} onClick={onRandomize}> | ||
Randomize | ||
</button> | ||
{/* <div className={classes.buttonContainer}> */} | ||
<select | ||
className={classes.buttonContainer} | ||
onChange={e => { | ||
let sortOption = e.target.value | ||
if (sortOptions[sortOption]) { | ||
sortOptions[sortOption]() | ||
} | ||
}} | ||
> | ||
<option value=''>Sort </option> | ||
<option value='ascending'>Ascending</option> | ||
<option value='descending'>Descending</option> | ||
</select> | ||
{/* </div> */} | ||
<NumberGenerator /> | ||
|
||
<input | ||
className={classes.arrayInput} | ||
type='text' | ||
placeholder='Numbers to sort (comma separate - max 3 digits)' | ||
type="text" | ||
placeholder="Numbers to sort (comma separate - max 3 digits)" | ||
value={input} | ||
onChange={onChange} | ||
onChange={onInputChange} | ||
/> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
export default ArrayInput | ||
export default ArrayInput; |
16 changes: 8 additions & 8 deletions
16
src/apps/sorting-visualizer/components/controller/controller.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.