Repository navigation
Implement JEE quiz interface with navigation and answer handling #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,265 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import Card from "../ui/Card"; | ||
| import Button from "../ui/Button"; | ||
| import ProgressBar from "../ui/Progressbar"; | ||
| import Timer from "../ui/Timer"; | ||
| import QuestionNavigation from "../ui/QuestionNavigation"; | ||
| import { Flag, ChevronRight } from "lucide-react"; | ||
|
|
||
| export default function Retentiaquiz() { | ||
|
|
||
| const totalQuestions = 50; | ||
|
|
||
| const [showSubmitModal, setShowSubmitModal] = useState(false); | ||
| const [currentQuestion, setCurrentQuestion] = useState(1); | ||
| const [answers, setAnswers] = useState<Record<number, string | null>>({}); | ||
| const [confirmedAnswers, setConfirmedAnswers] = useState<Record<number, boolean>>({}); | ||
| const [markedReview, setMarkedReview] = useState<Record<number, boolean>>({}); | ||
| const [skipped, setSkipped] = useState<Record<number, boolean>>({}); | ||
|
|
||
| const answeredCount = Object.keys(confirmedAnswers).length; | ||
|
|
||
| const options = [ | ||
| { id: "A", text: "Solar power" }, | ||
| { id: "B", text: "Wind Power" }, | ||
| { id: "C", text: "Natural Gas" }, | ||
| { id: "D", text: "Hydroelectric Power" }, | ||
| ]; | ||
|
|
||
| const confirmSubmit = () => { | ||
| setShowSubmitModal(false); | ||
|
|
||
| console.log("Quiz submitted successfully"); | ||
|
|
||
| }; | ||
|
|
||
| const handleOptionClick = (optionId: string) => { | ||
|
|
||
| setAnswers((prev) => { | ||
|
|
||
| const current = prev[currentQuestion]; | ||
|
|
||
| return { | ||
| ...prev, | ||
| [currentQuestion]: current === optionId ? null : optionId, | ||
| }; | ||
|
|
||
| }); | ||
|
|
||
| setSkipped((prev) => { | ||
| const updated = { ...prev }; | ||
| delete updated[currentQuestion]; | ||
| return updated; | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| const handleNext = () => { | ||
|
|
||
| if (answers[currentQuestion]) { | ||
|
|
||
| setConfirmedAnswers((prev) => ({ | ||
| ...prev, | ||
| [currentQuestion]: true, | ||
| })); | ||
|
|
||
| setSkipped((prev) => { | ||
| const updated = { ...prev }; | ||
| delete updated[currentQuestion]; | ||
| return updated; | ||
| }); | ||
|
|
||
| } else { | ||
|
|
||
| setSkipped((prev) => ({ | ||
| ...prev, | ||
| [currentQuestion]: true, | ||
| })); | ||
|
|
||
| setConfirmedAnswers((prev) => { | ||
| const updated = { ...prev }; | ||
| delete updated[currentQuestion]; | ||
| return updated; | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| if (currentQuestion < totalQuestions) { | ||
| setCurrentQuestion((prev) => prev + 1); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| const toggleReview = () => { | ||
|
|
||
| setMarkedReview((prev) => ({ | ||
| ...prev, | ||
| [currentQuestion]: !prev[currentQuestion], | ||
| })); | ||
|
|
||
| setSkipped((prev) => { | ||
| const updated = { ...prev }; | ||
| delete updated[currentQuestion]; | ||
| return updated; | ||
| }); | ||
|
|
||
| }; | ||
| const handleSubmit = () => { | ||
| setShowSubmitModal(true); | ||
| }; | ||
|
|
||
| return ( | ||
|
|
||
| <main className="min-h-screen flex flex-col justify-center bg-background py-10 | ||
| px-4 sm:px-10 md:px-20 lg:px-80"> | ||
|
|
||
| <div className="grid grid-cols-3 items-center mt-3 gap-4"> | ||
|
|
||
| <div></div> | ||
|
|
||
| <div className="flex justify-center"> | ||
| <Timer totalQuestions={totalQuestions} /> | ||
| </div> | ||
|
|
||
| <div className="flex justify-center sm:justify-end"> | ||
| <Button | ||
| variant="default" | ||
| className="bg-answered px-6 py-2 text-white" | ||
| onClick={handleSubmit} | ||
| > | ||
| Submit | ||
| </Button> | ||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
| <div className="mb-10 mt-10"> | ||
| <ProgressBar | ||
| answered={answeredCount} | ||
| total={totalQuestions} | ||
| /> | ||
| </div> | ||
|
|
||
| <QuestionNavigation | ||
| currentQuestion={currentQuestion} | ||
| totalQuestions={totalQuestions} | ||
| onQuestionChange={setCurrentQuestion} | ||
| confirmedAnswers={confirmedAnswers} | ||
| markedReview={markedReview} | ||
| skipped={skipped} | ||
| /> | ||
|
ItsAbhinavM marked this conversation as resolved.
|
||
|
|
||
| <Card | ||
| variant="primary" | ||
| className="w-full max-h-212.5 px-4 sm:px-6 md:px-10" | ||
| > | ||
|
|
||
| <Card | ||
| variant="secondary" | ||
| className="w-full mb-15 flex items-center justify-center" | ||
| > | ||
| <p className="text-xl sm:text-2xl md:text-3xl font-bold leading-relaxed p-6 sm:p-10 md:p-15 text-center"> | ||
| Which of the following energy sources cannot be | ||
| replenished naturally on a human timescale? | ||
| </p> | ||
| </Card> | ||
|
|
||
| <div className="space-y-5 text-lg sm:text-xl"> | ||
|
|
||
| {options.map((option) => { | ||
|
|
||
| const isSelected = answers[currentQuestion] === option.id; | ||
| const isAnswered = confirmedAnswers[currentQuestion]; | ||
|
|
||
| let colorClass = ""; | ||
|
|
||
| if (isAnswered && isSelected) colorClass = "border-secondary "; | ||
| else if (isSelected) colorClass = "border-secondary"; | ||
|
|
||
| return ( | ||
|
|
||
| <Button | ||
| key={option.id} | ||
| variant="opt_btn" | ||
| onClick={() => handleOptionClick(option.id)} | ||
| className={`${colorClass}`} | ||
| > | ||
|
|
||
| <div className="flex items-center justify-center w-8 h-8 rounded-full bg-white text-black font-semibold"> | ||
| {option.id} | ||
| </div> | ||
|
|
||
| <span className="flex-1 text-left"> | ||
| {option.text} | ||
| </span> | ||
|
|
||
| </Button> | ||
|
|
||
| ); | ||
| })} | ||
|
|
||
| </div> | ||
|
|
||
| </Card> | ||
|
|
||
| <div className="flex flex-col sm:flex-row justify-end items-center gap-5 mt-20 mb-5"> | ||
|
|
||
| <Button | ||
| variant="default" | ||
| onClick={toggleReview} | ||
| className="bg-purple-600 text-white px-6 py-2 flex items-center gap-2 w-full sm:w-auto justify-center" | ||
| > | ||
| <Flag size={18} /> | ||
| Mark For Review | ||
| </Button> | ||
|
|
||
| <Button | ||
| variant="default" | ||
| onClick={handleNext} | ||
| className="bg-secondary px-6 py-2 flex text-white items-center gap-2 w-full sm:w-auto justify-center" | ||
| > | ||
| Next Question | ||
| <ChevronRight size={18} /> | ||
| </Button> | ||
|
|
||
| </div> | ||
| {showSubmitModal && ( | ||
| <div className="fixed inset-0 bg-background flex items-center justify-center z-50"> | ||
| <Card variant="primary" className="p-8 max-w-md w-full text-center"> | ||
|
|
||
| <h2 className="text-xl font-bold mb-4"> | ||
| Submit Quiz? | ||
| </h2> | ||
|
|
||
| <p className="text-text mb-6"> | ||
| Are you sure you want to submit the quiz? | ||
| </p> | ||
|
|
||
| <div className="flex justify-center gap-4"> | ||
|
|
||
| <Button | ||
| variant="default" | ||
| onClick={() => setShowSubmitModal(false)} | ||
| > | ||
| Cancel | ||
| </Button> | ||
|
|
||
| <Button | ||
| variant="default" | ||
| className="bg-answered text-text" | ||
| onClick={confirmSubmit} | ||
| > | ||
| Submit | ||
| </Button> | ||
|
|
||
| </div> | ||
|
|
||
| </Card> | ||
| </div> | ||
| )} | ||
|
|
||
| </main> | ||
| ); | ||
| } | ||
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,23 @@ | ||
| type CardProps = { | ||
| children: React.ReactNode; | ||
| variant?: "primary" | "secondary"; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export default function Card({ | ||
| children, | ||
| variant = "primary", | ||
| className = "", | ||
| }: CardProps) { | ||
| const base = "rounded-3xl p-6 "; | ||
| const variants = { | ||
| primary: "bg-foreground flex overflow-y-auto flex-col text-text", | ||
| secondary: "bg-background/70 text-text", | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={`${base} ${variants[variant]} ${className}`}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } |
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,35 @@ | ||
| type ProgressBarProps = { | ||
| answered: number; | ||
| total: number; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export default function ProgressBar({ | ||
| answered, | ||
| total, | ||
| className = "", | ||
| }: ProgressBarProps) { | ||
|
|
||
| const progress = total > 0 ? (answered / total) * 100 : 0; | ||
|
|
||
| return ( | ||
| <div className={`w-full ${className}`}> | ||
|
|
||
|
|
||
| <div className="flex justify-between text-xl mb-1 text-text/70"> | ||
| <span>{answered} / {total} answered</span> | ||
| </div> | ||
|
|
||
|
|
||
| <div className="w-full h-4 rounded-full bg-text overflow-hidden"> | ||
|
|
||
| <div | ||
| className="h-full rounded-full bg-[#22C55E] transition-all duration-300 ease-out" | ||
| style={{ width: `${progress}%` }} | ||
| /> | ||
|
|
||
| </div> | ||
|
|
||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
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.