generated from dwd/boilarplate-remix-tailwind-antd
s1
This commit is contained in:
@@ -24,6 +24,16 @@ interface Module {
|
||||
moduleName: string;
|
||||
quizzes: Quiz[];
|
||||
}
|
||||
interface QuestionList {
|
||||
questionId: string;
|
||||
questionText: string;
|
||||
correctAnswer: string;
|
||||
options: string[];
|
||||
moduleId: string;
|
||||
}
|
||||
interface ModuleList {
|
||||
moduleId: string;
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
@@ -32,8 +42,59 @@ export default function Index() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const [questionList, setQuestionList] = useState<QuestionList[]>([]);
|
||||
const [moduleList, setModuleList] = useState<ModuleList[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`https://api.teachertrainingkolkata.in/api/question-list`)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error('Network Response not ok');
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then((questionData) => {
|
||||
setQuestionList(questionData);
|
||||
console.log('Question List', questionData);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error fetching question list:', error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (questionList.length > 0) {
|
||||
const fetchModuleList = async () => {
|
||||
try {
|
||||
const moduleData = await Promise.all(
|
||||
questionList.map((question) =>
|
||||
fetch(`https://api.teachertrainingkolkata.in/api/quiz-module-list?module_id=${question.moduleId}`)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error('Network Response not ok');
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
)
|
||||
);
|
||||
setModuleList(moduleData.flat());
|
||||
console.log('Module List', moduleData.flat());
|
||||
} catch (error) {
|
||||
console.error('Error fetching module list:', error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchModuleList();
|
||||
}
|
||||
}, [questionList]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
fetch('https://iimtt-api.s38.siliconpin.com/api/quiz-module')
|
||||
fetch('https://api.teachertrainingkolkata.in/api/quiz-module')
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
@@ -41,7 +102,7 @@ export default function Index() {
|
||||
return res.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('Fetched data:', data);
|
||||
// console.log('Fetched data:', data);
|
||||
// Extract the modules array from the response
|
||||
if (data && Array.isArray(data.modules)) {
|
||||
setQuizModuleData(data.modules);
|
||||
@@ -163,7 +224,7 @@ export default function Index() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{selectedQuiz.questions.map((questionData) => (
|
||||
{questionList.map((questionData) => (
|
||||
<div key={questionData.questionId} className="mb-4 px-10 flex flex-col space-y-2">
|
||||
<p className="text-[20px] font-[700]">
|
||||
Q{questionData.questionId}: {questionData.questionText}
|
||||
|
||||
Reference in New Issue
Block a user