Skip to content

Commit

Permalink
fix: use different methods to handle changing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Jan 21, 2024
1 parent 2c2eec5 commit 0fc0b83
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/components/Customizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,41 @@ type Props = {
};

export default function Customizer({ parameters, onChange }: Props) {
const handleParameterChange = (
event: React.ChangeEvent<HTMLInputElement>,
newValue?
) => {
const changeParameter = (name: string, newValue?) => {
const newParameters = parameters.map((parameter) => {
if (parameter.name === event.target.name) {
if (parameter.name === name) {
if (parameter.type === 'number') {
newValue = Number(newValue);
}

return {
...parameter,
value: newValue || event.target.value,
value: newValue,
};
}
return parameter;
});
onChange(newParameters);
};

const handleParameterChange = (
event: React.ChangeEvent<HTMLInputElement>,
newValue?

Check failure on line 42 in src/components/Customizer.tsx

View workflow job for this annotation

GitHub Actions / deploy

'newValue' is defined but never used
) => {
changeParameter(event.target.name, event.target.value);
};

const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
changeParameter(event.target.name, event.target.checked);
};

const handleAutocompleteChange = (
event: React.ChangeEvent<HTMLInputElement>,
newValue?
) => {
changeParameter(event.target.name, newValue);
};

// Group parameters
const groups = useMemo(
() =>
Expand Down Expand Up @@ -121,7 +140,7 @@ export default function Customizer({ parameters, onChange }: Props) {
options={[]}
multiple
value={parameter.value as string[] | number[] | boolean[]}
onChange={handleParameterChange}
onChange={handleAutocompleteChange}
renderInput={(params) => {
return (
<TextField
Expand Down Expand Up @@ -152,7 +171,7 @@ export default function Customizer({ parameters, onChange }: Props) {
control={
<Checkbox
name={parameter.name}
onChange={handleParameterChange}
onChange={handleCheckboxChange}
checked={parameter.value === true}
/>
}
Expand Down

0 comments on commit 0fc0b83

Please sign in to comment.