Skip to content

feat: add clear input button to reset form fields#669

Open
harshitha1106 wants to merge 1 commit into
AOSSIE-Org:mainfrom
harshitha1106:add-clear-input-button
Open

feat: add clear input button to reset form fields#669
harshitha1106 wants to merge 1 commit into
AOSSIE-Org:mainfrom
harshitha1106:add-clear-input-button

Conversation

@harshitha1106
Copy link
Copy Markdown

@harshitha1106 harshitha1106 commented Apr 19, 2026

Summary

Added a Clear Input button to reset the form fields to their default values.

Changes made

  • Clears the main text input
  • Resets difficulty to Easy Difficulty
  • Resets number of questions to 10
  • Resets the Wikipedia toggle to off
  • Clears the Google Doc URL field
  • Removes the selected question type from localStorage

Issue

Fixes #668

Testing

  • Verified the button resets the visible form fields
  • Verified selected question type is removed from localStorage

AI Usage Disclosure

  • This PR contains AI-generated code. I have read the AI Usage Policy and I have tested the code locally and I am responsible for it.

AI tools used: Perplexity

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions.
  • If applicable, I have made corresponding changes or additions to the documentation.
  • If applicable, I have made corresponding changes or additions to tests.
  • My changes generate no new warnings or errors.
  • I have joined the Discord server and shared this PR link there.
  • I have read the Contribution Guidelines.
  • Once I submit my PR, I will address CodeRabbit's comments.
  • I have filled this PR template carefully.

Summary by CodeRabbit

  • New Features
    • Added a "Clear Input" button to the text input interface. Users can now quickly reset all form inputs, difficulty selections, question counts, and related settings with a single click, enabling a fast way to start fresh when working on new content.

Added a clear input button to reset form fields and local storage values.Added a 'Clear Input' button that resets all form fields to their default values:
- Clears the text input field
- Resets difficulty to Easy Difficulty
- Resets number of questions to 10
- Resets Wikipedia toggle to off
- Clears Google Doc URL field
- Removes selected question type from localStorage

Fixes issue AOSSIE-Org#668
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

📝 Walkthrough

Walkthrough

A "Clear Input" button and associated handleClear function were added to the Text_Input component, enabling users to reset all form state variables (text, difficulty, numQuestions, isToggleOn, docUrl) and clear the selectedQuestionType localStorage key in a single click.

Changes

Cohort / File(s) Summary
Text Input Form Reset
eduaid_web/src/pages/Text_Input.jsx
Added handleClear function and "Clear Input" button that resets form state variables and clears the selectedQuestionType localStorage entry. Removed blank/comment lines with no control flow modifications.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A whisker-twitch of joy, oh what delight!
A button so clear, erasing input blight,
One hoppy click resets it all,
Form fields reset, localStorage falls—
Fresh like carrots, crisp and bright! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add clear input button to reset form fields' directly describes the main change - adding a Clear Input button functionality to reset all form fields.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #668 objectives: adds a Clear/Reset button, resets all form fields (text, difficulty, question count, toggle, doc URL) to defaults, and removes question type from localStorage without navigating away.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the clear input button feature; no unrelated modifications or scope creep detected in the Text_Input.jsx file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
eduaid_web/src/pages/Text_Input.jsx (1)

233-241: Add type="button" and accessibility affordances.

Minor hardening for the new button:

  • Explicitly set type="button" to prevent any accidental form-submit behavior if this subtree is ever wrapped in a <form>.
  • Consider an aria-label (the visible text is fine, but a confirmation step could be worth considering since clicking this destroys all user-entered content with no undo).
Proposed diff
           <button
+            type="button"
             onClick={handleClear}
             className="bg-[`#7600F2`] text-white text-lg sm:text-xl px-6 py-2 rounded-xl border border-[`#00CBE7`] hover:bg-[`#7600F2`]/80 transition-all"
           >
             Clear Input
           </button>
🤖 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 233 - 241, The Clear Input
button lacks an explicit type and accessibility affordances: update the JSX
button element that calls handleClear to include type="button" and an
appropriate aria-label (e.g., "Clear input") and/or aria-describedby for
additional context; to prevent accidental data loss, either add a confirmation
step by wrapping the onClick to call a small confirm wrapper (e.g.,
prompt/confirm before invoking handleClear) or implement the confirmation inside
the handleClear handler itself so users must confirm before the handler clears
user-entered content.
🤖 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 48-55: handleClear is removing selectedQuestionType from
localStorage which is set on Question_Type.jsx and required later (sendToBackend
-> getEndpoint and Output.jsx); either stop deleting that key in handleClear so
it remains available, or add a guard in handleSaveToLocalStorage/sendToBackend
to detect a missing selectedQuestionType and prompt the user to pick one before
proceeding. Also, if fileContent should be part of the cleared form state, reset
fileContent in handleClear to keep form state consistent. Refer to handleClear,
selectedQuestionType, handleSaveToLocalStorage, sendToBackend, getEndpoint, and
fileContent when making the change.

---

Nitpick comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 233-241: The Clear Input button lacks an explicit type and
accessibility affordances: update the JSX button element that calls handleClear
to include type="button" and an appropriate aria-label (e.g., "Clear input")
and/or aria-describedby for additional context; to prevent accidental data loss,
either add a confirmation step by wrapping the onClick to call a small confirm
wrapper (e.g., prompt/confirm before invoking handleClear) or implement the
confirmation inside the handleClear handler itself so users must confirm before
the handler clears user-entered content.
🪄 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: fdfb6b35-7a9a-4927-8c90-5ffc013ef6ad

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and 90a10dc.

📒 Files selected for processing (1)
  • eduaid_web/src/pages/Text_Input.jsx

Comment on lines +48 to +55
const handleClear = () => {
setText("");
setDifficulty("Easy Difficulty");
setNumQuestions(10);
setIsToggleOn(0);
setDocUrl("");
localStorage.removeItem("selectedQuestionType");
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Clearing selectedQuestionType may leave the app in a broken state.

handleClear removes selectedQuestionType from localStorage, but this value is set on a different page (Question_Type.jsx) and is required downstream. If a user clicks "Clear Input" and then "Next" without navigating back to re-select a question type, sendToBackend will be called with questionType === null, producing a request to /null (see Line 79 and getEndpoint at Line 96), and the subsequent Output page initializes its state from this same key (eduaid_web/src/pages/Output.jsx:8-12), breaking the Q&A formatting logic at lines 123-153.

Consider either:

  1. Not clearing selectedQuestionType in handleClear (it's set on a separate screen and arguably isn't part of "the input form" being cleared), or
  2. Guarding handleSaveToLocalStorage against a missing selectedQuestionType and prompting the user to pick one.

Also note that fileContent state is not reset here — if it's intended to be part of the cleared form state, it should be included for consistency.

Proposed minimal fix
   const handleClear = () => {
     setText("");
     setDifficulty("Easy Difficulty");
     setNumQuestions(10);
     setIsToggleOn(0);
     setDocUrl("");
-    localStorage.removeItem("selectedQuestionType");
+    setFileContent("");
   };
🤖 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 48 - 55, handleClear is
removing selectedQuestionType from localStorage which is set on
Question_Type.jsx and required later (sendToBackend -> getEndpoint and
Output.jsx); either stop deleting that key in handleClear so it remains
available, or add a guard in handleSaveToLocalStorage/sendToBackend to detect a
missing selectedQuestionType and prompt the user to pick one before proceeding.
Also, if fileContent should be part of the cleared form state, reset fileContent
in handleClear to keep form state consistent. Refer to handleClear,
selectedQuestionType, handleSaveToLocalStorage, sendToBackend, getEndpoint, and
fileContent when making the change.

@harshitha1106
Copy link
Copy Markdown
Author

Hi maintainers,
This PR has been open for a while. Could someone please review or let me know if any changes are needed? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GOOD FIRST ISSUE]: Add a "Clear Input" button to reset the text input form

1 participant