Model Of Data Changed

main
Pedram Keshavarzi 3 years ago
parent b1a9772338
commit 68c61ddccd
  1. 62
      src/redux/reducers/exam.js
  2. 47
      src/view/addExam/views/AddQuestionsFromBank.js

@ -48,11 +48,13 @@ const initialState = {
courseBank: [ courseBank: [
{ {
id: 1, id: 1,
title: 'ریاضی' title: 'ریاضی',
selectedQuestions: []
}, },
{ {
id: 2, id: 2,
title: 'شیمی' title: 'شیمی',
selectedQuestions: []
}, },
], ],
questionBank: [ questionBank: [
@ -143,6 +145,35 @@ const initialState = {
}, },
] ]
}, },
{
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: [ courses: [
@ -155,7 +186,7 @@ const initialState = {
} }
export default function addExamReduser(state = initialState, { type, payload }) { export default function addExamReduser(state = initialState, { type, payload }) {
console.log(state.courses)
switch (type) { switch (type) {
case 'ADD_EXAM_GRADE_AND_GROUP': case 'ADD_EXAM_GRADE_AND_GROUP':
return { return {
@ -209,15 +240,30 @@ export default function addExamReduser(state = initialState, { type, payload })
} }
case 'ADD_EXAM_QUESTIONS': 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]}
const newCourses = [...othercourses, ...selectedC]
return { return {
...state, ...state,
questions : [...state.questions, payload] courses: newCourses
} }
case 'REMOVE_EXAM_QUESTIONS': 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)}
const newCoursesWithDeleted = [...dontDeleteThese, ...courseForDelete]
console.log(newCoursesWithDeleted)
console.log(payload)
return { return {
...state, ...state,
questions: state.questions.filter(itm => itm.questionId !== payload.questionId) courses: newCoursesWithDeleted
} }
case 'REMOVE_QUESTION_FROM_BANK': case 'REMOVE_QUESTION_FROM_BANK':
return { return {
@ -230,6 +276,12 @@ export default function addExamReduser(state = initialState, { type, payload })
questionBank : [...state.questionBank, payload] questionBank : [...state.questionBank, payload]
} }
case 'CHANGE_QUESTION_ORDER':
return{
...state,
questions: payload
}
default: default:
return state; return state;

@ -26,7 +26,8 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
const [choosedQuestion, seChoosedQuestion] = useState(null); const [choosedQuestion, seChoosedQuestion] = useState(null);
const [selectedCourse, setSelectedCourse] = useState({ const [selectedCourse, setSelectedCourse] = useState({
id: null, id: null,
title: '' title: '',
selectedQuestions: [],
}); });
const [answers, setAnswers] = useState(null); const [answers, setAnswers] = useState(null);
const [newCourse, setNewCourse] = useState({ const [newCourse, setNewCourse] = useState({
@ -36,13 +37,17 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
name: '', name: '',
coefficient: 4 coefficient: 4
}) })
// console.log(choosedQuestionaries) // console.log(choosedQuestionaries)
// console.log(newQuestionaire) // console.log(newQuestionaire)
// console.log(addExamState.questionnaires) // console.log(addExamState.questionnaires)
console.log(newCourse) // console.log(newCourse)
console.log(addExamState.questionairesCourses) // console.log(addExamState.questionairesCourses)
console.log(selectedCourse) console.log(selectedCourse)
console.log(answers) // console.log(answers)
console.log(choosedQuestion)
console.log(selectedCourse.selectedQuestions)
const [fakeState, setFakeState] = useState(2); const [fakeState, setFakeState] = useState(2);
@ -71,9 +76,24 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
} }
}else{ }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.questions];
const [removed] = aaa.splice(aaa.indexOf(itm => itm.questionId == source.index), 1);
aaa.splice(aaa.indexOf(itm=> itm.questionId == destination.index), 0, removed);
dispatch({type: 'CHANGE_QUESTION_ORDER', payload: aaa})
console.log(result) console.log(result)
} }
} }
}
console.log(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions)
return ( return (
<> <>
@ -197,7 +217,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
{ {
console.log(result) console.log(result)
if(result.source.droppableId == 'Choosed_Questions_Form_Bank'){ if(result.source.droppableId == 'Choosed_Questions_Form_Bank'){
seChoosedQuestion(addExamState.questions.find(itm => itm.questionId == result.source.index)) seChoosedQuestion(addExamState.courses.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions?.find(itm => itm.questionId == result.source.index))
}else{ }else{
seChoosedQuestion(addExamState.questionBank.find(itm => itm.questionId == result.source.index)) seChoosedQuestion(addExamState.questionBank.find(itm => itm.questionId == result.source.index))
} }
@ -213,11 +233,11 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
<h1 className="text-blue3A w-full font-bold text-lg text-right"> <h1 className="text-blue3A w-full font-bold text-lg text-right">
{selectedCourse.title} {selectedCourse.title}
</h1> </h1>
<div className="flex flex-col items-center overflow-x-hidden overflow-scroll" style={{ height: '500px' }}> <div className="flex flex-col items-center ">
<div className="w-4/5 "> <div className="w-4/5 ">
{ {
addExamState.questions.filter(itm => itm.courseId == selectedCourse.id).map( addExamState.courses?.filter(itm => itm.id == selectedCourse.id)[0]?.selectedQuestions?.map(
(item, index) => ( (item, index) => (
<Draggable draggableId={`_${item.questionId}`} index={item.questionId} key={`CHOOSED_QUESTIONS_${index}`}> <Draggable draggableId={`_${item.questionId}`} index={item.questionId} key={`CHOOSED_QUESTIONS_${index}`}>
{(provided) => ( {(provided) => (
@ -232,6 +252,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
</div> </div>
</div> </div>
{provided.placeholder}
</>) </>)
} }
{/* {selectedQuestionare.id !== null && {/* {selectedQuestionare.id !== null &&
@ -240,7 +261,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
افزودن درس افزودن درس
</button> </button>
</div>} */} </div>} */}
{provided.placeholder}
</div> </div>
)} )}
@ -254,20 +275,14 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
{/* <AnswerSheet questionsQuantity={selectedCourse.questionsQuantity} optionsQuantity={4} selectedCourseId={selectedCourse.id} {/* <AnswerSheet questionsQuantity={selectedCourse.questionsQuantity} optionsQuantity={4} selectedCourseId={selectedCourse.id}
passAnswers={data => {setAnswers(data); setFakeState(fakeState - 2)}}/> */} passAnswers={data => {setAnswers(data); setFakeState(fakeState - 2)}}/> */}
{selectedCourse.id !== null && {selectedCourse.id !== null &&
addExamState.questionBank.filter(itm => itm.courseId == selectedCourse.id).map( addExamState.questionBank?.filter(itm => itm.courseId == selectedCourse.id)?.map(
(course, index) => ( (course, index) => (
<Draggable draggableId={`_${course.questionId}`} index={course.questionId} key={`CHOOSED_QUESTIONS_${course.questionId}`}> <Draggable draggableId={`_${course.questionId}`} index={course.questionId} key={`CHOOSED_QUESTIONS_${course.questionId}`}>
{(provided) => ( {(provided) => (
<div className="flex items-start justify-between w-full">
<div {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef} className="flex items-start justify-center w-full">
<div {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef}>
<Question data={course} /> <Question data={course} />
</div> </div>
</div>
)} )}
</Draggable> </Draggable>
) )

Loading…
Cancel
Save