-
-
Notifications
You must be signed in to change notification settings - Fork 418
Feat(ui): add pre-generation quiz review and confirmation flow #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
piyush06singhal
wants to merge
8
commits into
AOSSIE-Org:main
Choose a base branch
from
piyush06singhal:feature/quiz-review-confirmation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83de70d
chore: ignore large models tar.gz files in backend
piyush06singhal 0e68957
feat: add quiz review and confirmation step before generation
piyush06singhal 5effadd
fix: address CodeRabbit review comments
piyush06singhal a79067f
fix: add payload validation, trim inputs, prevent error persistance
piyush06singhal 106a3fb
fix: harden numQuestions hydration and validate question count before…
piyush06singhal a37949f
fix the hydration and duplication error
piyush06singhal abe6b69
fix the minor UI errors
piyush06singhal 838f968
fix minor serError issues
piyush06singhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import "../index.css"; | ||
| import logo_trans from "../assets/aossie_logo_transparent.png"; | ||
| import { Link, useNavigate } from "react-router-dom"; | ||
| import apiClient from "../utils/apiClient"; | ||
|
|
||
| const Review = () => { | ||
| const navigate = useNavigate(); | ||
| const [loading, setLoading] = useState(false); | ||
| const [reviewData, setReviewData] = useState({ | ||
| text: "", | ||
| difficulty: "", | ||
| numQuestions: 0, | ||
| questionType: "", | ||
| useWikipedia: false, | ||
| inputSource: "Text" | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const text = localStorage.getItem("textContent") || ""; | ||
| const difficulty = localStorage.getItem("difficulty") || "Easy Difficulty"; | ||
| const savedNumQuestions = localStorage.getItem("numQuestions"); | ||
| const parsedNumQuestions = Number.parseInt(savedNumQuestions ?? "", 10); | ||
| const numQuestions = Number.isInteger(parsedNumQuestions) && parsedNumQuestions > 0 ? parsedNumQuestions : 10; | ||
| const questionType = localStorage.getItem("selectedQuestionType") || ""; | ||
| const useWikipedia = localStorage.getItem("useWikipedia") === "1"; | ||
| const savedInputSource = localStorage.getItem("inputSource"); | ||
|
|
||
| let inputSource = savedInputSource || "text"; | ||
| if (!savedInputSource) { | ||
| if (text.includes("uploaded file") || text.includes("Error uploading")) { | ||
| inputSource = "file"; | ||
| } else if (text.includes("Google Doc")) { | ||
| inputSource = "url"; | ||
| } | ||
| } | ||
|
|
||
| setReviewData({ | ||
| text, | ||
| difficulty, | ||
| numQuestions, | ||
| questionType, | ||
| useWikipedia, | ||
| inputSource | ||
| }); | ||
|
|
||
| if (!text || !questionType) { | ||
| navigate("/input"); | ||
| } | ||
| }, [navigate]); | ||
|
|
||
| const getInputSourceLabel = (source) => { | ||
| const labels = { | ||
| text: "Text", | ||
| file: "File Upload", | ||
| url: "Google Doc URL" | ||
| }; | ||
| return labels[source] || "Text"; | ||
| }; | ||
|
|
||
| const getQuestionTypeLabel = (type) => { | ||
| const types = { | ||
| get_shortq: "Short-Answer Type Questions", | ||
| get_mcq: "Multiple Choice Questions", | ||
| get_boolq: "True/False Questions", | ||
| get_problems: "All Questions" | ||
| }; | ||
| return types[type] || type; | ||
| }; | ||
|
|
||
| const getEndpoint = (difficulty, questionType) => { | ||
| if (difficulty !== "Easy Difficulty") { | ||
| if (questionType === "get_shortq") { | ||
| return "get_shortq_hard"; | ||
| } else if (questionType === "get_mcq") { | ||
| return "get_mcq_hard"; | ||
| } | ||
| } | ||
| return questionType; | ||
| }; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleConfirmGenerate = async () => { | ||
| setLoading(true); | ||
| const endpoint = getEndpoint(reviewData.difficulty, reviewData.questionType); | ||
|
|
||
| const allowedEndpoints = ["get_shortq", "get_mcq", "get_boolq", "get_problems", "get_shortq_hard", "get_mcq_hard"]; | ||
| if (!allowedEndpoints.includes(endpoint)) { | ||
| console.error("Invalid endpoint:", endpoint); | ||
| setLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| const trimmedText = reviewData.text.trim(); | ||
| if (!trimmedText || !Number.isInteger(reviewData.numQuestions) || reviewData.numQuestions <= 0) { | ||
| console.error("Invalid generation payload"); | ||
| setLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const requestData = { | ||
| input_text: trimmedText, | ||
| max_questions: reviewData.numQuestions, | ||
| use_mediawiki: reviewData.useWikipedia ? 1 : 0, | ||
| }; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const responseData = await apiClient.post(`/${endpoint}`, requestData); | ||
| localStorage.setItem("qaPairs", JSON.stringify(responseData)); | ||
|
|
||
| const quizDetails = { | ||
| difficulty: reviewData.difficulty, | ||
| numQuestions: reviewData.numQuestions, | ||
| date: new Date().toLocaleDateString(), | ||
| qaPair: responseData, | ||
| }; | ||
|
|
||
| let last5Quizzes = []; | ||
| try { | ||
| const stored = localStorage.getItem("last5Quizzes"); | ||
| if (stored) { | ||
| const parsed = JSON.parse(stored); | ||
| if (Array.isArray(parsed)) { | ||
| last5Quizzes = parsed; | ||
| } | ||
| } | ||
| } catch (parseError) { | ||
| console.error("Failed to parse last5Quizzes:", parseError); | ||
| } | ||
|
|
||
| last5Quizzes.push(quizDetails); | ||
| if (last5Quizzes.length > 5) { | ||
| last5Quizzes.shift(); | ||
| } | ||
| localStorage.setItem("last5Quizzes", JSON.stringify(last5Quizzes)); | ||
|
|
||
| navigate("/output"); | ||
| } catch (error) { | ||
| console.error("Error:", error); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="popup bg-[#02000F] bg-custom-gradient min-h-screen"> | ||
| {loading && ( | ||
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-opacity-50 bg-black"> | ||
| <div className="loader border-4 border-t-4 border-white rounded-full w-16 h-16 animate-spin"></div> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className={`w-full h-full bg-cust bg-opacity-50 ${loading ? "pointer-events-none" : ""}`}> | ||
| <Link to="/" className="block"> | ||
| <div className="flex items-end gap-2 p-4"> | ||
| <img src={logo_trans} alt="logo" className="w-20 sm:w-24" /> | ||
| <div className="text-3xl sm:text-4xl font-extrabold"> | ||
| <span className="bg-gradient-to-r from-[#FF005C] to-[#7600F2] text-transparent bg-clip-text">Edu</span> | ||
| <span className="bg-gradient-to-r from-[#7600F2] to-[#00CBE7] text-transparent bg-clip-text">Aid</span> | ||
| </div> | ||
| </div> | ||
| </Link> | ||
|
|
||
| <div className="text-white text-center mx-4 sm:mx-8 mb-6"> | ||
| <div className="text-2xl sm:text-3xl font-bold">Review Your Configuration</div> | ||
| <p className="text-lg sm:text-xl mt-2">Please confirm the details before generating questions</p> | ||
| </div> | ||
|
|
||
| <div className="max-w-3xl mx-auto px-4 sm:px-8"> | ||
| <div className="bg-[#83b6cc40] rounded-2xl p-6 space-y-4"> | ||
| <div className="border-b border-gray-600 pb-4"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-1">Input Source</div> | ||
| <div className="text-white text-lg sm:text-xl font-semibold">{getInputSourceLabel(reviewData.inputSource)}</div> | ||
| </div> | ||
|
|
||
| <div className="border-b border-gray-600 pb-4"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-1">Question Type</div> | ||
| <div className="text-white text-lg sm:text-xl font-semibold"> | ||
| {getQuestionTypeLabel(reviewData.questionType)} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="border-b border-gray-600 pb-4"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-1">Number of Questions</div> | ||
| <div className="text-white text-lg sm:text-xl font-semibold">{reviewData.numQuestions}</div> | ||
| </div> | ||
|
|
||
| <div className="border-b border-gray-600 pb-4"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-1">Difficulty Level</div> | ||
| <div className="text-white text-lg sm:text-xl font-semibold">{reviewData.difficulty}</div> | ||
| </div> | ||
|
|
||
| <div className="pb-2"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-1">Use Wikipedia</div> | ||
| <div className="text-white text-lg sm:text-xl font-semibold"> | ||
| {reviewData.useWikipedia ? "Yes" : "No"} | ||
| </div> | ||
| </div> | ||
|
|
||
| {reviewData.text && ( | ||
| <div className="pt-4 border-t border-gray-600"> | ||
| <div className="text-[#E4E4E4] text-sm sm:text-base mb-2">Content Preview</div> | ||
| <div className="text-white text-sm sm:text-base bg-[#1a1a2e] p-4 rounded-lg max-h-32 overflow-y-auto"> | ||
| {reviewData.text.substring(0, 200)} | ||
| {reviewData.text.length > 200 && "..."} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="flex flex-col sm:flex-row justify-center gap-6 mt-8 pb-10"> | ||
| <Link to="/input"> | ||
| <button className="bg-black text-white text-lg sm:text-xl px-6 py-3 border-gradient rounded-xl w-full sm:w-auto"> | ||
| Back to Edit | ||
| </button> | ||
| </Link> | ||
| <button | ||
| onClick={handleConfirmGenerate} | ||
| disabled={loading} | ||
| className={`text-white text-lg sm:text-xl px-6 py-3 rounded-xl w-full sm:w-auto ${loading | ||
| ? "bg-gray-500 cursor-not-allowed" | ||
| : "bg-gradient-to-r from-[#FF005C] via-[#7600F2] to-[#00CBE7] hover:brightness-110" | ||
| }`} | ||
| > | ||
| {loading ? "Generating..." : "Confirm & Generate"} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Review; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.