|
1 | | -import { Select, Text, Spacer } from "@geist-ui/react" |
2 | | -import { SortingAlgorithms } from "../types" |
3 | | - |
4 | 1 | // @ts-ignore |
5 | 2 | import styles from "../styles/Home.module.scss" |
6 | 3 |
|
7 | | -const algorithms: SortingAlgorithms[] = ["Selection", "Insertion", "Bubble"] |
| 4 | +import { Select, Text, Spacer } from "@geist-ui/react" |
| 5 | +import { SortingAlgorithms } from "../types" |
| 6 | +import { useControlsDisabled } from "../hooks" |
| 7 | +import { ALGORITHMS_LIST } from "../constants" |
8 | 8 |
|
9 | 9 | interface Props { |
10 | | - disabled: boolean |
11 | | - selectedAlgorithm: string | string[] |
12 | | - onChangeHandler: (algorithm: string | string[]) => void |
| 10 | + selectedAlgorithm: SortingAlgorithms |
| 11 | + onChange: (algorithm: SortingAlgorithms) => void |
13 | 12 | } |
14 | 13 |
|
15 | | -export const AlgorithmSelector: React.FC<Props> = (props) => { |
16 | | - let { disabled, selectedAlgorithm, onChangeHandler } = props |
17 | | - |
18 | | - const selectOptions = algorithms.map((algorithm, idx) => ( |
| 14 | +const getSelectOptionsFromAlgorithmsList = (algorithmsList: SortingAlgorithms[]) => { |
| 15 | + const selectOptions = algorithmsList.map((algorithm, idx) => ( |
19 | 16 | <Select.Option key={idx} value={algorithm}> |
20 | | - {`${algorithm} Sort`} |
| 17 | + {`${algorithm} sort`} |
21 | 18 | </Select.Option> |
22 | 19 | )) |
23 | 20 |
|
| 21 | + return selectOptions |
| 22 | +} |
| 23 | + |
| 24 | +export const AlgorithmSelector: React.FC<Props> = ({ selectedAlgorithm, onChange }) => { |
| 25 | + const isControlsDisabled = useControlsDisabled() |
| 26 | + const selectOptions = getSelectOptionsFromAlgorithmsList(ALGORITHMS_LIST) |
| 27 | + |
24 | 28 | return ( |
25 | 29 | <div className={styles.sideBarInputContainer}> |
26 | 30 | <Text>Select Algorithm</Text> |
27 | 31 | <Spacer y={-0.4} /> |
28 | 32 | <Select |
29 | | - disabled={disabled} |
30 | | - value={selectedAlgorithm} |
31 | | - onChange={(algorithm) => onChangeHandler(algorithm)} |
32 | | - size="large"> |
| 33 | + disabled={isControlsDisabled} |
| 34 | + onChange={(algorithm) => onChange(algorithm as SortingAlgorithms)} |
| 35 | + size="large" |
| 36 | + value={selectedAlgorithm}> |
33 | 37 | {selectOptions} |
34 | 38 | </Select> |
35 | 39 | </div> |
|
0 commit comments