Skip to content

Commit 740709d

Browse files
committed
Added error message timeout for input validation
1 parent 9fabd24 commit 740709d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/components/AlgorithmForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default function AlgorithmForm() {
6868

6969
if (values.length === 0) {
7070
setErrorMessage("Please enter a sorted array of integers.");
71+
setTimeout(() => setErrorMessage(null), 2000);
7172
return;
7273
}
7374

@@ -77,22 +78,25 @@ export default function AlgorithmForm() {
7778
const invalidNumber = arr.some((value) => Number.isNaN(value) || !Number.isInteger(value));
7879
if (invalidNumber) {
7980
setErrorMessage("Array must contain only integers.");
81+
setTimeout(() => setErrorMessage(null), 2000);
8082
return;
8183
}
8284

8385
if (Number.isNaN(target) || !Number.isInteger(target)) {
8486
setErrorMessage("Target must be an integer.");
87+
setTimeout(() => setErrorMessage(null), 2000);
8588
return;
8689
}
8790

8891
const isSorted = arr.every((value, index) => index === 0 || value >= arr[index - 1]);
8992
if (!isSorted) {
9093
setErrorMessage("Array must be sorted in ascending order.");
94+
setTimeout(() => setErrorMessage(null), 2000);
9195
return;
9296
}
9397

9498
setAbort(false);
95-
visualizeBinarySearch(arr, target, 'root', 0, arr.length - 1, 0, -200, 200);
99+
visualizeBinarySearch(arr, target, 'root', 0, arr.length - 1, 0);
96100
setOngoingVisualization(true);
97101
return;
98102
}

0 commit comments

Comments
 (0)