diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index 4dc2953..d4add57 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -10,15 +10,15 @@ const initialState = { endTime: '', description: '', type: 'bank', - + questionnaires: [ { - id:1, + id: 1, name: 'عمومی', fileUrl: '', }, { - id:2, + id: 2, name: 'اختصاصی', fileUrl: '', } @@ -27,14 +27,14 @@ const initialState = { { id: 0, questionnaireId: 1, - questionsQuantity:20, + questionsQuantity: 20, name: 'دینی', coefficient: 4 }, { id: 1, questionnaireId: 2, - questionsQuantity:20, + questionsQuantity: 20, name: 'ریاضی', coefficient: 4, }, @@ -42,7 +42,7 @@ const initialState = { ], answers: [ - + ], courseBank: [ @@ -61,132 +61,132 @@ const initialState = { { questionId: 1, courseId: 2, - title:'تترا فلورید اسید چنتا اسید داره؟', + title: 'تترا فلورید اسید چنتا اسید داره؟', answeredPercentage: '83%', score: 1, options: [ { id: 1, - title:'تترا', + title: 'تترا', isAnswer: false }, { id: 2, - title:'سه ترا', + title: 'سه ترا', isAnswer: false }, { id: 3, - title:'هویج و گوجه فرنگی؟', + title: 'هویج و گوجه فرنگی؟', isAnswer: true }, { id: 4, - title:'فلور تا', + title: 'فلور تا', isAnswer: false }, - ] + ] }, { questionId: 2, courseId: 2, - title:'asdaw dsfsdfiermc', + title: 'asdaw dsfsdfiermc', answeredPercentage: '83%', score: 1, options: [ { id: 1, - title:'asdasd', + title: 'asdasd', isAnswer: false }, { id: 2, - title:'asdasd2', + title: 'asdasd2', isAnswer: false }, { id: 3, - title:'', + title: '', isAnswer: true }, { id: 4, - title:'asdasd4', + title: 'asdasd4', isAnswer: false }, - ] + ] }, { questionId: 3, courseId: 1, - title:'برای حل مساءل مربوط به مساحت زیر نمودار باید از کدام مبحث ریاضی استفاده کرد؟', + title: 'برای حل مساءل مربوط به مساحت زیر نمودار باید از کدام مبحث ریاضی استفاده کرد؟', answeredPercentage: '43%', score: 1, options: [ { id: 1, - title:'لگاریتم طبیعی', + title: 'لگاریتم طبیعی', isAnswer: false }, { id: 2, - title:'حد و مشتق', + title: 'حد و مشتق', isAnswer: false }, { id: 3, - title:'قدر مطلق', + title: 'قدر مطلق', isAnswer: false }, { id: 4, - title:'نخوندم 🗿', + title: 'نخوندم 🗿', isAnswer: true }, - ] + ] }, { questionId: 4, courseId: 2, - title:'asdaw dsfsdfisdfsdfsfsdfsfsdfsdfermc', + title: 'asdaw dsfsdfisdfsdfsfsdfsfsdfsdfermc', answeredPercentage: '83%', score: 1, options: [ { id: 1, - title:'asdasd', + title: 'asdasd', isAnswer: false }, { id: 2, - title:'asdasd2', + title: 'asdasd2', isAnswer: false }, { id: 3, - title:'sdfsdfsdfsfd', + title: 'sdfsdfsdfsfd', isAnswer: true }, { id: 4, - title:'asdasd4', + title: 'asdasd4', isAnswer: false }, - ] + ] }, - + ], courses: [ ], questions: [ - + ] } export default function addExamReduser(state = initialState, { type, payload }) { - console.log(state.courses) + console.log(state.courses) switch (type) { case 'ADD_EXAM_GRADE_AND_GROUP': return { @@ -206,88 +206,94 @@ export default function addExamReduser(state = initialState, { type, payload }) description: payload.description, type: payload.type } - + case 'ADD_EXAM_QUESTIONAIRES': return { ...state, questionnaires: [...state.questionnaires, payload] } - case 'ADD_QUESTIONNAIRE_COURSES' : + case 'ADD_QUESTIONNAIRE_COURSES': return { ...state, questionairesCourses: [ ...state.questionairesCourses, payload ] - } + } case 'ADD_ANSWERS': - return{ - ...state, + return { + ...state, answers: [ ...state.answers, payload ] - } + } case 'ADD_EXAM_COURSE': return { ...state, courses: [...state.courses, payload] - } - case 'REMOVE_EXAM_COURSE': + } + case 'REMOVE_EXAM_COURSE': return { ...state, courses: state.courses.filter(itm => itm.id !== payload.id) } - + case 'ADD_EXAM_QUESTIONS': console.log(payload) 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: [...selectedC[0].selectedQuestions, payload]} + selectedC[0] = { ...selectedC[0], selectedQuestions: [...selectedC[0].selectedQuestions, payload] } const newCourses = [...othercourses, ...selectedC] return { ...state, - courses: newCourses - + courses: newCourses + } - - - case 'REMOVE_EXAM_QUESTIONS': - const dontDeleteThese = state.courses.filter(itm => itm.id !== payload.courseId) + + + 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) + 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': + 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 : [...state.questionBank, payload] - } + case 'GET_QUESTION_BACK_TO_BANK': + return { + ...state, + questionBank: [...state.questionBank, payload] + } - case 'CHANGE_QUESTION_ORDER': - const dontChangeThese = state.courses.filter(itm => itm.id !== payload[0].courseId) + 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] + courseForChange[0] = { ...courseForChange[0], selectedQuestions: payload } + const newChangedCourseSort = [...dontChangeThese, ...courseForChange] console.log(payload) - return{ - ...state, - courses: newChangedCourseSort - } + return { + ...state, + courses: newChangedCourseSort + } + case 'CHANGE_COURSE_ORDER': + console.log(payload) + return { + ...state, + courses: payload + } default: diff --git a/src/view/addExam/views/AddQuestionsFromBank.js b/src/view/addExam/views/AddQuestionsFromBank.js index 30449fd..f4ff910 100644 --- a/src/view/addExam/views/AddQuestionsFromBank.js +++ b/src/view/addExam/views/AddQuestionsFromBank.js @@ -10,13 +10,14 @@ import RangeDatePicker from "../../../components/RangeDatePicker"; import SelectedCourse from "../../../components/selectedCourse"; import AddQuestionnaireCourse from "../components/addQuestionnaireCourse"; import Question from "../components/question"; +import AddQuestionPopUp from "../components/addQuestion"; const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backStep }) => { const [name, setName] = useState(null); const [type, setType] = useState(null); const [description, setDescription] = useState(null); const [questionarePopUp, setQuestionairePopUp] = useState(false); - const [addCoursePopup, setAddCoursePopup] = useState(false); + const [addQuestionPopup, setAddQuestionPopuo] = useState(false); const [newQuestionaire, setNewQuestionaire] = useState({ id: addExamState.questionnaires.length + 1, name: '', @@ -38,7 +39,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS coefficient: 4 }) - + // console.log(choosedQuestionaries) // console.log(newQuestionaire) // console.log(addExamState.questionnaires) @@ -62,43 +63,43 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS const payload = { name: name, description: description, type: type }; - const handleOnDragEnd = (result) => { - const {source, destination} = result; - - if(source.droppableId !== destination.droppableId){ - if(destination.droppableId == 'Choosed_Questions_Form_Bank'){ - dispatch({ type: 'ADD_EXAM_QUESTIONS', payload: choosedQuestion }) - dispatch({ type: 'REMOVE_QUESTION_FROM_BANK', payload: choosedQuestion }) - - }else{ - dispatch({ type: 'REMOVE_EXAM_QUESTIONS', payload: choosedQuestion }) - dispatch({type: 'GET_QUESTION_BACK_TO_BANK', payload: choosedQuestion}) - } - - }else{ - if(source.droppableId == 'Choosed_Questions_Form_Bank'){ - // const data = { - // startIndex: choosedQuestion, - // endIndex: destination.index - // } - // dispatch({type:'CHANGE_QUESTION_ORDER', payload : data}) - // console.log(data) - - const aaa = [...addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions]; - const [removed] = aaa.splice( source.index, 1); - - aaa.splice(destination.index, 0, removed); - dispatch({type: 'CHANGE_QUESTION_ORDER', payload: aaa}) - console.log(result) - console.log(source.index) - console.log(destination.index) - console.log(aaa) - + const handleOnDragEnd = (result) => { + const { source, destination } = result; + + if (source.droppableId !== destination.droppableId) { + if (destination.droppableId == 'Choosed_Questions_Form_Bank') { + dispatch({ type: 'ADD_EXAM_QUESTIONS', payload: choosedQuestion }) + dispatch({ type: 'REMOVE_QUESTION_FROM_BANK', payload: choosedQuestion }) + + } else { + dispatch({ type: 'REMOVE_EXAM_QUESTIONS', payload: choosedQuestion }) + dispatch({ type: 'GET_QUESTION_BACK_TO_BANK', payload: choosedQuestion }) + } + + } else { + if (source.droppableId == 'Choosed_Questions_Form_Bank') { + // const data = { + // startIndex: choosedQuestion, + // endIndex: destination.index + // } + // dispatch({type:'CHANGE_QUESTION_ORDER', payload : data}) + // console.log(data) + + const aaa = [...addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions]; + const [removed] = aaa.splice(source.index, 1); + + aaa.splice(destination.index, 0, removed); + dispatch({ type: 'CHANGE_QUESTION_ORDER', payload: aaa }) + console.log(result) + console.log(source.index) + console.log(destination.index) + console.log(aaa) + + } } - } - } + } -console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions) + console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions) return ( <> { @@ -117,7 +118,7 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.

- افزودن دفترچه + افزودن درس

@@ -165,14 +166,10 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?. } { - // addCoursePopup && - // setAddCoursePopup(false)} - // nameOnChange={e => setNewCourse({...newCourse, name: e.target.value})} - // coefficientOnChange={e => setNewCourse({...newCourse, coefficient: e.target.vlaue})} - // questionQuantityOnChange={e => setNewCourse({...newCourse, questionsQuantity: e.target.value, questionnaireId: selectedQuestionare.id})} - // submitOnClick={() => {dispatch({type: 'ADD_QUESTIONNAIRE_COURSES', payload : newCourse}); setAddCoursePopup(false); setFakeState(fakeState + 356)} } - // /> + addQuestionPopup && + setAddQuestionPopuo(false)} + /> } @@ -185,25 +182,68 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.

لطفا مشخضات آزمون را تکمیل کنید

+ { + const {source, destination} = result; + if (source.droppableId == 'Choosed_Courses_Form_Bank') { + // const data = { + // startIndex: choosedQuestion, + // endIndex: destination.index + // } + // dispatch({type:'CHANGE_QUESTION_ORDER', payload : data}) + // console.log(data) + + const aaa = [...addExamState.courses]; + const [removed] = aaa.splice(source.index, 1); + + aaa.splice(destination.index, 0, removed); + dispatch({ type: 'CHANGE_COURSE_ORDER', payload: aaa }) + console.log(result) + console.log(source.index) + console.log(destination.index) + console.log(aaa) + + } + }} + > + + {(provided) => ( +
+ {provided.placeholder} +
+ {addExamState.courses.length > 0 && + addExamState.courses.map( + (item, index) => ( + + {(provided) => ( +
setSelectedCourse(item)} + > +

+ { dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item }); setSelectedCourse(null); setFakeState(fakeState + 24) }}> x +

+ +

+ {item.title} +

+
+ + )} + +
+ )) + + } + +
- {addExamState.courses.length > 0 && - addExamState.courses.map( - (item => ( -
setSelectedCourse(item)} - > -

dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item })}> - x -

- -

- {item.title} -

-
- )) - ) - } +
+ )} +
+
setQuestionairePopUp(true)}>

+ @@ -213,19 +253,20 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.

+ +
- handleOnDragEnd(result)} - onDragStart={(result) => - { - console.log(result) - if(result.source.droppableId == 'Choosed_Questions_Form_Bank'){ - seChoosedQuestion(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions[result.source.index]) - }else{ - seChoosedQuestion(addExamState.questionBank.find(itm => itm.questionId == result.source.index)) - } - }}> + handleOnDragEnd(result)} + onDragStart={(result) => { + console.log(result) + if (result.source.droppableId == 'Choosed_Questions_Form_Bank') { + seChoosedQuestion(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions[result.source.index]) + } else { + seChoosedQuestion(addExamState.questionBank.find(itm => itm.questionId == result.source.index)) + } + }}>
{(provided) => ( @@ -245,7 +286,7 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?. (item, index) => ( {(provided) => ( -
+
)} @@ -253,19 +294,20 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?. ) ) } + {provided.placeholder}
- {provided.placeholder} + ) } - {/* {selectedQuestionare.id !== null && + {selectedCourse.id !== null &&
- -
} */} - + } + )} @@ -274,28 +316,36 @@ console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?. {(provided) => ( +
+ -
- {/* {setAnswers(data); setFakeState(fakeState - 2)}}/> */} - {selectedCourse.id !== null && - addExamState.questionBank?.filter(itm => itm.courseId == selectedCourse.id)?.map( - (course, index) => ( - - {(provided) => ( - -
- -
- )} -
- ) - ) + {selectedCourse.id !== null && <> +
+ { + addExamState.questionBank?.filter(itm => itm.courseId == selectedCourse.id)?.map( + (course, index) => ( + + {(provided) => ( + +
+ +
+ )} +
+ ) + ) + } + +
+ + } {/* */} - {provided.placeholder} + {provided.placeholder}
+ + )}