Skip to content

Commit 4112d35

Browse files
committed
FIXED:#49 Modifed create quiz ui to enable minutes and seconds input
Changes Made: - Removed default timer (600 seconds = 10 minutes) - Added 2 input fields to take seperate minutes and seconds - Converted them into seconds and set them to customTimer variable
1 parent 1083bcb commit 4112d35

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

app/components/Fileinput.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ function FileInput({ onFileUpload }: FileInputProps) {
3535
id: uuidv4(),
3636
isDeleted: false,
3737
isLocked: false,
38-
customTimer: 600, // Default value in seconds
38+
customTimer: 0, // Default value in seconds
3939
} as QuizInfo);
4040
const [quizGenerated, setQuizGenerated] = useState(false);
4141
const [viewQuizData, setViewQuizData] = useState(false);
4242
const [fileName, setFileName] = useState("");
43+
const [timerInput, setTimerInput] = useState({ minutes: "", seconds: "" });
4344

4445
const onDrop = (acceptedFiles: any) => {
4546
const file = acceptedFiles[0];
@@ -82,15 +83,24 @@ function FileInput({ onFileUpload }: FileInputProps) {
8283
const { name, value } = e.target;
8384
setQuizInfo({
8485
...quizInfo,
85-
[name]: name === "customTimer" ? parseInt(value, 10) : value, // Ensure customTimer is an integer
86+
[name]: value,
87+
});
88+
};
89+
90+
const handleTimerInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
91+
const { name, value } = e.target;
92+
setTimerInput({
93+
...timerInput,
94+
[name]: value,
8695
});
8796
};
8897

8998
const { getRootProps, getInputProps } = useDropzone({ onDrop });
9099

91100
const generateQuiz = () => {
92101
if (quizInfo.quizName && quizInfo.course && quizInfo.courseCode && excelData) {
93-
onFileUpload({ ...quizInfo, quizData: excelData, fileName });
102+
const totalSeconds = (parseInt(timerInput.minutes) * 60) + parseInt(timerInput.seconds);
103+
onFileUpload({ ...quizInfo, customTimer: totalSeconds, quizData: excelData, fileName });
94104
setQuizGenerated(true);
95105
router.push("/");
96106
} else {
@@ -135,10 +145,18 @@ function FileInput({ onFileUpload }: FileInputProps) {
135145
/>
136146
<input
137147
type="number"
138-
name="customTimer"
139-
value={quizInfo.customTimer}
140-
placeholder="Custom Timer (seconds)"
141-
onChange={handleInputChange}
148+
name="minutes"
149+
value={timerInput.minutes}
150+
placeholder="Minutes"
151+
onChange={handleTimerInputChange}
152+
className="text-black bg-slate-500 w-full m-2 p-2 rounded"
153+
/>
154+
<input
155+
type="number"
156+
name="seconds"
157+
value={timerInput.seconds}
158+
placeholder="Seconds"
159+
onChange={handleTimerInputChange}
142160
className="text-black bg-slate-500 w-full m-2 p-2 rounded"
143161
/>
144162
</div>

0 commit comments

Comments
 (0)