Loading...
;
@@ -51,6 +52,34 @@ const QuestionPaperDashboard = () => {
0
);
+
+ const deleteQuestion=async (question)=>
+ {
+ console.log(question);
+ try
+ {
+ await axios.post('http://localhost:5000/paper/delete-question', { _id: question._id })
+ setQuestions((prevQuestions) => prevQuestions.filter(q => q._id !== question._id));
+
+ if (questions.length === 1) {
+ setQuestions([]);
+ }
+
+ setReload(prev => !prev);
+ }
+ catch(error)
+ {
+ console.error('Error creating paper:', error);
+ }
+ }
+
+ const duplicateQuestion= async (question)=>
+ {
+ console.log(question);
+ await axios.post(`http://localhost:5000/paper/duplicate-question`, { question})
+ setReload(prev => !prev);
+
+ }
const handleSubmit = () => {
// Here, you would handle the submit logic.
// Trigger a success modal on successful submission
@@ -98,6 +127,8 @@ const QuestionPaperDashboard = () => {
{question.questionDescription}
+
diff --git a/src/papers/papers.jsx b/src/papers/papers.jsx
index 1b37df9..6f8c632 100644
--- a/src/papers/papers.jsx
+++ b/src/papers/papers.jsx
@@ -8,6 +8,8 @@ import Nothing from "../Assets/nothing.svg";
function Papers() {
const navigate = useNavigate();
const [exams, setExams] = useState([]);
+ const [reload,setReload]= useState(false);
+
const teacherId = localStorage.getItem("teacherId"); // Assuming teacherId is stored in localStorage
useEffect(() => {
@@ -24,12 +26,63 @@ function Papers() {
};
fetchPapers();
- }, [teacherId]);
+ }, [teacherId,reload]);
const handleCreateNew = () => {
navigate("/create-paper");
};
+ const handleEditNew=(exam)=>
+ {
+ navigate(
+ "/edit-paper",
+ {
+ state:
+ {
+ _id:exam._id,
+ className:exam.className,
+ semester:exam.semester,
+ subject:exam.subject,
+ subjectCode:exam.subjectCode,
+ date:exam.date,
+ duration:exam.duration,
+ testType:exam.testType,
+ marks:exam.marks,
+ time:exam.time
+ }
+ }
+ );
+ }
+
+
+ const deletePaper=async (paper)=>
+ {
+
+ try
+ {
+ await axios.post('http://localhost:5000/paper/delete-paper', { _id: paper._id })
+ setExams((prevQuestions) => prevQuestions.filter(q => q._id !== paper._id));
+
+ if (paper.length === 1) {
+ setExams([]);
+ }
+
+ setReload(prev => !prev);
+
+ }
+ catch(error)
+ {
+ console.error('Error creating paper:', error);
+ }
+ }
+
+ const duplicatePaper = async (paper)=>
+ {
+ await axios.post("http://localhost:5000/paper/duplicate-paper",paper);
+ setReload(prev => !prev);
+ }
+
+
const getFormattedDateTime = (date, time) => {
const [hours, minutes] = time.split(":").map(Number);
const dateTime = new Date(date);
@@ -90,6 +143,30 @@ function Papers() {
{exam.duration.minutes} mins