Add direct numeric input for "Number of Questions" (Enhancement #647)#648
Add direct numeric input for "Number of Questions" (Enhancement #647)#648MANVENDRA-github wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis change replaces a read-only question count display with an editable numeric input that enforces a minimum of 1, persists sanitized values to localStorage, and sends a validated integer Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
eduaid_web/src/pages/Text_Input.jsx (1)
83-89:⚠️ Potential issue | 🟠 MajorIncrement/decrement functions don't handle empty string state.
The new input allows
numQuestionsto temporarily be an empty string (line 221), but these functions weren't updated:
incrementQuestions:"" + 1produces"1"(string), not1(number)decrementQuestions: allows value to reach0, inconsistent withmin={1}validationProposed fix
const incrementQuestions = () => { - setNumQuestions((prev) => prev + 1); + setNumQuestions((prev) => (typeof prev === "number" ? prev : 1) + 1); }; const decrementQuestions = () => { - setNumQuestions((prev) => (prev > 0 ? prev - 1 : 0)); + setNumQuestions((prev) => { + const current = typeof prev === "number" ? prev : 1; + return current > 1 ? current - 1 : 1; + }); };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@eduaid_web/src/pages/Text_Input.jsx` around lines 83 - 89, incrementQuestions and decrementQuestions don't handle when numQuestions is the empty string: update both to coerce the current state to a number (e.g., use Number(...) or parseInt(...) with a fallback) before arithmetic, and ensure the result never drops below the minimum 1 (consistent with the input's min={1}). Specifically, in incrementQuestions call setNumQuestions with a function that converts prev to a numeric value defaulting to 1 then adds 1; in decrementQuestions convert prev to a numeric value defaulting to 1 then subtract 1 but clamp the result to a minimum of 1 before calling setNumQuestions.
🧹 Nitpick comments (1)
eduaid_web/src/pages/Text_Input.jsx (1)
67-69: Consider validating before storing to localStorage.Similar to the backend concern,
numQuestionscould be an empty string when stored. If other code reads this value expecting a number, it could cause issues.Proposed fix
localStorage.setItem("textContent", text); localStorage.setItem("difficulty", difficulty); -localStorage.setItem("numQuestions", numQuestions); +localStorage.setItem("numQuestions", typeof numQuestions === "number" && numQuestions >= 1 ? numQuestions : 1);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@eduaid_web/src/pages/Text_Input.jsx` around lines 67 - 69, Validate and normalize values before writing to localStorage: ensure numQuestions is parsed to an integer (e.g., using parseInt) and falls back to a sensible default or is not stored if invalid, and ensure text and difficulty are non-empty/expected types; update the localStorage.setItem calls in the Text_Input component to store the normalized/validated values (referencing variables text, difficulty, numQuestions) instead of raw inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 213-236: numQuestions can be an empty string when the user clears
the field and immediately clicks Next, so validate and coerce it just before
sending to backend: in handleSaveToLocalStorage (and/or the function that calls
sendToBackend), parse numQuestions with parseInt(Number(...)) or Number() and if
result is NaN or <1 set to 1, then pass that numeric value as max_questions to
identify_keywords/sendToBackend; also add a defensive type check in the backend
call site that expects max_questions to be a number.
---
Outside diff comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 83-89: incrementQuestions and decrementQuestions don't handle when
numQuestions is the empty string: update both to coerce the current state to a
number (e.g., use Number(...) or parseInt(...) with a fallback) before
arithmetic, and ensure the result never drops below the minimum 1 (consistent
with the input's min={1}). Specifically, in incrementQuestions call
setNumQuestions with a function that converts prev to a numeric value defaulting
to 1 then adds 1; in decrementQuestions convert prev to a numeric value
defaulting to 1 then subtract 1 but clamp the result to a minimum of 1 before
calling setNumQuestions.
---
Nitpick comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 67-69: Validate and normalize values before writing to
localStorage: ensure numQuestions is parsed to an integer (e.g., using parseInt)
and falls back to a sensible default or is not stored if invalid, and ensure
text and difficulty are non-empty/expected types; update the
localStorage.setItem calls in the Text_Input component to store the
normalized/validated values (referencing variables text, difficulty,
numQuestions) instead of raw inputs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f1a0778e-3088-47b9-80ac-dbe5b9a55a42
📒 Files selected for processing (2)
eduaid_web/src/index.csseduaid_web/src/pages/Text_Input.jsx
Fixes #647
Summary
This PR enhances the "Number of Questions" input by allowing users to directly enter a numeric value instead of relying solely on increment/decrement buttons.
Changes Made
Added alongside existing +/- controls
Implemented validation (minimum value = 1)
Handled edge cases (empty input, invalid values)
Removed default browser spinner UI for consistency
Preserved existing functionality (backward compatible)
Problem
Previously, users had to click the "+" button repeatedly to reach larger values, leading to poor UX.
Solution
Introduced a hybrid input system:
Direct typing for efficiency
Buttons for quick adjustments
Before:
After:
Summary by CodeRabbit
New Features
Style