Changing The Order Of Questions Done

main
Pedram Keshavarzi 3 years ago
parent 68c61ddccd
commit 0e05d5a0b6
  1. 11
      src/redux/reducers/exam.js
  2. 16
      src/view/addExam/views/AddQuestionsFromBank.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
}

@ -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) => (
<Draggable draggableId={`_${item.questionId}`} index={item.questionId} key={`CHOOSED_QUESTIONS_${index}`}>
<Draggable draggableId={`_${item.questionId}`} index={index} key={`CHOOSED_QUESTIONS_${item.questionId}`}>
{(provided) => (
<div {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef}>
<Question data={item} />

Loading…
Cancel
Save