You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

402 lines
9.6 KiB

import { IoReturnUpBack } from "react-icons/io5";
import fizikpdf from "../../assets/fizik.pdf";
import samplePdf from "../../assets/sample.pdf";
const initialState = {
grade: 8,
groupId: 0,
name: "",
startDate: new Date(),
endDate: new Date(),
startTime: "19:0",
endTime: "",
description: "",
type: "bank",
duration: null,
budgetFileId: null,
questionnaires: [
// {
// id: 1,
// name: "عمومی",
// fileUrl: fizikpdf,
// courses: [
// {
// id: 0,
// questionnaireId: 1,
// name: "دینی",
// coefficient: 4,
// questionStart: 1,
// questionEnd: 21,
// },
// ],
// answers: [],
// },
// {
// id: 2,
// name: "اختصاصی",
// fileUrl: samplePdf,
// courses: [],
// answers: [],
// },
],
answers: [],
courseBank: [
// {
// id: 1,
// title: 'ریاضی',
// coefficient: 4,
// numberOfOptions: 4,
// selectedQuestions: []
// },
// {
// id: 2,
// title: 'شیمی',
// coefficient: 3,
// numberOfOptions: 3,
// selectedQuestions: []
// },
],
questionBank: [
{
questionId: 1,
courseId: 2,
title: "تترا فلورید اسید چنتا اسید داره؟",
answeredPercentage: "83%",
score: 1,
options: [
{
id: 1,
title: "تترا",
isAnswer: false,
},
{
id: 2,
title: "سه ترا",
isAnswer: false,
},
{
id: 3,
title: "هویج و گوجه فرنگی؟",
isAnswer: true,
},
{
id: 4,
title: "فلور تا",
isAnswer: false,
},
],
},
{
questionId: 2,
courseId: 2,
title: "asdaw dsfsdfiermc",
answeredPercentage: "83%",
score: 1,
options: [
{
id: 1,
title: "asdasd",
isAnswer: false,
},
{
id: 2,
title: "asdasd2",
isAnswer: false,
},
{
id: 3,
title: "",
isAnswer: true,
},
{
id: 4,
title: "asdasd4",
isAnswer: false,
},
],
},
{
questionId: 3,
courseId: 1,
title:
"برای حل مساءل مربوط به مساحت زیر نمودار باید از کدام مبحث ریاضی استفاده کرد؟",
answeredPercentage: "43%",
score: 1,
options: [
{
id: 1,
title: "لگاریتم طبیعی",
isAnswer: false,
},
{
id: 2,
title: "حد و مشتق",
isAnswer: false,
},
{
id: 3,
title: "قدر مطلق",
isAnswer: false,
},
{
id: 4,
title: "نخوندم 🗿",
isAnswer: true,
},
],
},
{
questionId: 4,
courseId: 2,
title: "asdaw dsfsdfisdfsdfsfsdfsfsdfsdfermc",
answeredPercentage: "83%",
score: 1,
options: [
{
id: 1,
title: "asdasd",
isAnswer: false,
},
{
id: 2,
title: "asdasd2",
isAnswer: false,
},
{
id: 3,
title: "sdfsdfsdfsfd",
isAnswer: true,
},
{
id: 4,
title: "asdasd4",
isAnswer: false,
},
],
},
],
courses: [],
questions: [],
};
export const numOfinitQs = initialState.questionBank.length;
export default function addExamReduser(
state = initialState,
{ type, payload }
) {
switch (type) {
case "ADD_EXAM_GRADE_AND_GROUP":
return {
...state,
grade: payload.grade,
groupId: payload.groupId,
};
case "ADD_EXAM_DESCRIPTION":
return {
...state,
name: payload.name,
startDate: new Date(),
endDate: new Date(),
startTime: "19:0",
endTime: "",
description: payload.description,
type: payload.type,
duration: payload.duration,
startDate: payload.startDate,
endDate: payload.endDate,
budgetFileId: payload.budgetFileId,
};
case "ADD_EXAM_QUESTIONAIRES":
return {
...state,
questionnaires: [...state.questionnaires, payload],
};
case "ADD_QUESTIONNAIRE_COURSES":
console.log(payload);
let thisQ = state.questionnaires.find(
(itm) => itm.id == payload.questionnaireId
);
let otherQ = state.questionnaires.filter(
(itm) => itm.id !== payload.questionnaireId
);
thisQ = {
...thisQ,
courses: thisQ?.courses?.length ? [...thisQ?.courses, payload] :[payload],
};
console.log(thisQ);
return {
...state,
questionnaires: [...otherQ, thisQ],
};
case "ADD_ANSWERS":
console.log(payload);
let thisQC = state.questionnaires.find(
(itm) => itm.id == payload[0].questionnaierId
);
let otherQC = state.questionnaires.filter(
(itm) => itm.id !== payload[0].questionnaierId
);
thisQC = {
...thisQC,
answers: [...thisQC?.answers, ...payload],
};
return {
...state,
questionnaires: [...otherQC, thisQC],
};
case "ADD_EXAM_COURSE":
return {
...state,
courses: [...state.courses, { ...payload, selectedQuestions: [] }],
};
case "REMOVE_EXAM_COURSE":
return {
...state,
courses: state.courses.filter((itm) => itm.id !== payload.id),
};
case "ADD_EXAM_QUESTIONS":
console.log("??????????????");
console.log(payload);
console.log(state.courses);
const othercourses = state.courses.filter(
(itm) => itm.id !== payload.lessonId
);
const selectedC = state.courses.filter(
(itm) => itm.id == payload.lessonId
);
selectedC[0] = {
...selectedC[0],
selectedQuestions: [payload, ...selectedC[0].selectedQuestions],
};
const newCourses = [...othercourses, ...selectedC];
return {
...state,
courses: newCourses,
};
case "ADD_EXAM_QUESTIONS2":
let newList = state.questions;
let isNew = true;
for(let i=0;i<newList.length;i++){
if(newList[i].examId===payload.examId){
newList[i].list = [...newList[i].list, payload.item];
isNew=false
}
}
if(isNew){
newList.push({
examId: payload.examId,
list: [payload.item],
});
}
return {
...state,
questions: newList,
};
case "REMOVE_EXAM_QUESTIONS":
const dontDeleteThese = state.courses.filter(
(itm) => itm.id !== payload.courseId
);
const courseForDelete = state.courses.filter(
(itm) => itm.id == payload.courseId
);
courseForDelete[0] = {
...courseForDelete[0],
selectedQuestions: courseForDelete[0].selectedQuestions.filter(
(itm) => itm.questionId !== payload.questionId
),
};
const newCoursesWithDeleted = [...dontDeleteThese, ...courseForDelete];
console.log(newCoursesWithDeleted);
console.log(courseForDelete);
console.log(dontDeleteThese);
console.log(payload);
return {
...state,
courses: newCoursesWithDeleted,
};
case "REMOVE_QUESTION_FROM_BANK":
return {
...state,
questionBank: state.questionBank.filter(
(itm) => itm.questionId !== payload.questionId
),
};
case "GET_QUESTION_BACK_TO_BANK":
return {
...state,
questionBank: [payload, ...state.questionBank],
};
case "CHANGE_QUESTION_ORDER":
const dontChangeThese = state.courses.filter(
(itm) => itm.id !== payload[0].courseId
);
const courseForChange = state.courses.filter(
(itm) => itm.id == payload[0].courseId
);
courseForChange[0] = {
...courseForChange[0],
selectedQuestions: payload,
};
const newChangedCourseSort = [...dontChangeThese, ...courseForChange];
console.log(payload);
return {
...state,
courses: newChangedCourseSort,
};
case "CHANGE_COURSE_ORDER":
console.log(payload);
return {
...state,
courses: payload,
};
case "ADD_CUSTOM_QUESTION":
const otherCourses = state.courses.filter(
(itm) => itm.id !== payload.courseId
);
const selectedc = state.courses.filter(
(itm) => itm.id == payload.courseId
);
selectedc[0] = {
...selectedc[0],
selectedQuestions: [payload, ...selectedc[0].selectedQuestions],
};
const newcourses = [...selectedc, ...otherCourses];
return {
...state,
courses: newcourses,
};
case "CHANGE_COURSE_NUM_OF_OPTIONS":
const otherCourseS = state.courses.filter(
(itm) => itm.id !== payload.courseId
);
const seLectedC = state.courses.filter(
(itm) => itm.id == payload.courseId
);
seLectedC[0] = { ...seLectedC[0], numberOfOptions: payload.value };
const neWCourses = [...seLectedC, ...otherCourseS];
return {
...state,
courses: neWCourses,
};
case "CHANGE_QUESTIONNAIRES_ORDER":
return {
...state,
questionnaires: payload,
};
default:
return state;
}
}