import React, { useState } from "react"; import { QuestionApi } from "../Services/Api"; import EditExamModal from "./EditExamModal"; import { useEffect } from "react"; const Carousel = ({ data }) => { console.log(data) const [questionList, setQuestionList] = useState(data); const [updatedAnswer, setUpdatedAnswer] = useState(); const [currentIndex, setCurrentIndex] = useState(0); const nextSlide = () => { setCurrentIndex((currentIndex + 1) % data.length); }; const prevSlide = () => { setCurrentIndex((currentIndex - 1 + data.length) % data.length); }; const deleteQuestion = async (id) => { const response = await QuestionApi(`/DeleteQuestion/${id}`, { method: "DELETE", headers: { "Content-Type": "application/json", }, }); if (response.ok) { await setQuestionList((questionList) => { const updatedList = questionList.filter((item) => item.id !== id); if ( updatedList.length === 0 || currentIndex === questionList.length - 1 ) { setCurrentIndex(0); } return updatedList; }); } else { console.log("Sınav Silme Başarısız"); } }; const updateToQuestion = async (id, name, answer, examId) => { const updatedData = { id: id, content: name, allAnswer: JSON.stringify(updatedAnswer), examId: examId, }; const jsonData = JSON.stringify(updatedData); const response = await QuestionApi(`/UpdateQuestion/${id}`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: jsonData, }); if (!response.ok) { console.log("Güncelleme işlemi başarısız."); } }; const trueAnswer = JSON.parse(data[currentIndex].allAnswer).find( (answer) => answer.IsTrue ); return (

{data[currentIndex].content}

Doğru Cevap: {trueAnswer.Text}

); }; export default Carousel;