import React, { useState } from “react”;
import { Card, CardContent } from “@/components/ui/card”;
import { Button } from “@/components/ui/button”;
import { Input } from “@/components/ui/input”;
import * as XLSX from “xlsx”;
export default function QuizUploader() {
const [questions, setQuestions] = useState([]);
const handleFileUpload = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = (evt) => {
const bstr = evt.target.result;
const wb = XLSX.read(bstr, { type: “binary” });
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
const data = XLSX.utils.sheet_to_json(ws);
const newQuestions = data.map((row) => ({
question: row.Question,
options: [row.OptionA, row.OptionB, row.OptionC, row.OptionD],
answer: row.Answer,
}));
setQuestions((prev) => […prev, …newQuestions]);
};
reader.readAsBinaryString(file);
};
return (
🧠 Quiz Upload & Preview
{questions.map((q, index) => (
Q{index + 1}: {q.question}
{q.options.map((opt, idx) => (
- {opt}
))}
✔️ Correct Answer: {q.answer}
))}
);
}