Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-grace committed Nov 14, 2024
1 parent 7e96116 commit fcc4f6a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/components/BluetoothPatternInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ const BluetoothPatternInput = ({

const columnInputOnChange = useCallback(
(colIdx: number): ((value: string) => void) => {
return (v) => {
const inputValsCopy = [...inputValues];
const cleanedValue = v.replace("-", "").replace("+", "");
inputValsCopy[colIdx] = cleanedValue;
const colValue = parseInt(v) || 0;
if (colValue > 5 || colValue < 0) {
return (value) => {
const colValue = value === "" ? 0 : parseInt(value);
if (isNaN(colValue) || colValue > 5 || colValue < 0) {
// Do nothing when input value is not valid.
return;
}
setInputValues(inputValsCopy);
setInputValues(inputValues.map((v, i) => (i === colIdx ? value : v)));
updateMatrix(colIdx, matrixDim - colValue);
};
},
Expand Down

0 comments on commit fcc4f6a

Please sign in to comment.