diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index e0d06a4..4dc2953 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -256,9 +256,11 @@ export default function addExamReduser(state = initialState, { type, payload }) 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.id !== payload.id)} + 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, @@ -277,9 +279,14 @@ export default function addExamReduser(state = initialState, { type, payload }) } 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, - questions: payload + courses: newChangedCourseSort } diff --git a/src/view/addExam/views/AddQuestionsFromBank.js b/src/view/addExam/views/AddQuestionsFromBank.js index 124ecb8..30449fd 100644 --- a/src/view/addExam/views/AddQuestionsFromBank.js +++ b/src/view/addExam/views/AddQuestionsFromBank.js @@ -84,17 +84,21 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS // dispatch({type:'CHANGE_QUESTION_ORDER', payload : data}) // console.log(data) - const aaa = [...addExamState.questions]; - const [removed] = aaa.splice(aaa.indexOf(itm => itm.questionId == source.index), 1); + const aaa = [...addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions]; + const [removed] = aaa.splice( source.index, 1); - aaa.splice(aaa.indexOf(itm=> itm.questionId == destination.index), 0, removed); + 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 ( <> { @@ -217,7 +221,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS { console.log(result) if(result.source.droppableId == 'Choosed_Questions_Form_Bank'){ - seChoosedQuestion(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions?.find(itm => itm.questionId == result.source.index)) + 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)) } @@ -239,7 +243,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS { addExamState.courses?.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions?.map( (item, index) => ( - + {(provided) => (