From b36bc037d311d7e3420de9610a2e9730d5175c41 Mon Sep 17 00:00:00 2001 From: Pkpedram Date: Tue, 1 Mar 2022 19:54:00 +0330 Subject: [PATCH] Adding Questions Done --- src/redux/reducers/exam.js | 25 +-- .../addExam/views/AddQuestionsFromBank.js | 142 ++++++++++-------- 2 files changed, 96 insertions(+), 71 deletions(-) diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index 179464f..d190a25 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -149,7 +149,7 @@ const initialState = { ], questions: [ - + ] } @@ -175,16 +175,7 @@ export default function addExamReduser(state = initialState, { type, payload }) description: payload.description, type: payload.type } - case 'ADD_EXAM_QUESTIONS': - return { - ...state, - name: payload.name, - startDate: new Date(), - endDate: new Date(), - startTime: '19:0', - endTime: '', - description: payload.description, - } + case 'ADD_EXAM_QUESTIONAIRES': return { ...state, @@ -216,6 +207,18 @@ export default function addExamReduser(state = initialState, { type, payload }) ...state, courses: state.courses.filter(itm => itm.id !== payload.id) } + + case 'ADD_EXAM_QUESTIONS': + return { + ...state, + questions : [...state.questions, payload] + } + + case 'REMOVE_EXAM_QUESTIONS': + return { + ...state, + questions: state.questions.filter(itm => itm.questionId !== payload.questionId) + } default: return state; diff --git a/src/view/addExam/views/AddQuestionsFromBank.js b/src/view/addExam/views/AddQuestionsFromBank.js index dfb8917..f484fa6 100644 --- a/src/view/addExam/views/AddQuestionsFromBank.js +++ b/src/view/addExam/views/AddQuestionsFromBank.js @@ -24,14 +24,14 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS const [showCoursesInList, setShowCoursesInList] = useState([]); const [choosedQuestionaries, seChoosedQuestionaries] = useState([]); const [selectedCourse, setSelectedCourse] = useState({ - id: null, + id: null, title: '' }); const [answers, setAnswers] = useState(null); const [newCourse, setNewCourse] = useState({ id: addExamState.questionairesCourses.length + 1, questionnaireId: selectedCourse.id, - questionsQuantity:20, + questionsQuantity: 20, name: '', coefficient: 4 }) @@ -42,21 +42,21 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS console.log(addExamState.questionairesCourses) console.log(selectedCourse) console.log(answers) - + const [fakeState, setFakeState] = useState(2); useEffect(() => { // questoinaresLists.map(item => showCoursesInList.push(false)); - if(answers !== null && answers !== []) { - answers.map(item => dispatch({type: 'ADD_ANSWERS', payload : item})) + if (answers !== null && answers !== []) { + answers.map(item => dispatch({ type: 'ADD_ANSWERS', payload: item })) } - + }, [answers]) const payload = { name: name, description: description, type: type }; - + return ( <> @@ -78,31 +78,31 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS

افزودن دفترچه

- - - { - addExamState.courseBank.map( - (item, index) => ( - <> -
- - e.target.checked ? - dispatch({type: 'ADD_EXAM_COURSE', payload: item}) - : - - dispatch({type: 'REMOVE_EXAM_COURSE', payload: item}) + { + addExamState.courseBank.map( + (item, index) => ( + <> +
+ + e.target.checked ? + dispatch({ type: 'ADD_EXAM_COURSE', payload: item }) + : - } - /> -

{item.title}

- {/*

تعداد سوالات: {item.numberOfQuestions}

+ dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item }) + + + } + + /> +

{item.title}

+ {/*

تعداد سوالات: {item.numberOfQuestions}

تعداد دروس: {item.courses.length}

*/} - {/*

{ + {/*

{ let newArray = [...showCoursesInList]; newArray[index] = !newArray[index]; @@ -112,15 +112,15 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS }}>نمایش دروس

*/} -
- - - ) +
+ + ) - } - - - + ) + } + + + } { @@ -133,7 +133,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS // submitOnClick={() => {dispatch({type: 'ADD_QUESTIONNAIRE_COURSES', payload : newCourse}); setAddCoursePopup(false); setFakeState(fakeState + 356)} } // /> - + }
@@ -149,16 +149,16 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS addExamState.courses.map( (item => (
setSelectedCourse(item)} - > -

dispatch({type: 'REMOVE_EXAM_COURSE', payload: item})}> + onClick={() => setSelectedCourse(item)} + > +

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

- -

- {item.title} -

-
+

+ +

+ {item.title} +

+
)) ) } @@ -168,7 +168,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS +

- افزودن درس + افزودن درس

@@ -179,27 +179,28 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
- {/* { - selectedQuestionare.id !== null && (<> + { + selectedCourse.id !== null && (<>

- دفترچه {selectedQuestionare.name} + {selectedCourse.title}

{ - addExamState.questionairesCourses.filter(itm => itm.questionnaireId == selectedQuestionare.id).map( + addExamState.questions.filter(itm => itm.courseId == selectedCourse.id).map( (item) => ( - {setSelectedCourse(item); console.log(selectedCourse)}}/> + + ) ) }
+
) } - {selectedQuestionare.id !== null && + {/* {selectedQuestionare.id !== null &&
- {/* {setAnswers(data); setFakeState(fakeState - 2)}}/> */} -{selectedCourse.id !== null && - addExamState.questionBank.filter(itm => itm.courseId == selectedCourse.id).map( - (course) => () - ) -} - {/* */} + {selectedCourse.id !== null && + addExamState.questionBank.filter(itm => itm.courseId == selectedCourse.id).map( + (course , index) => ( + +
+ + e.target.checked ? + dispatch({ type: 'ADD_EXAM_QUESTIONS', payload: course }) + // console.log('asodjasd') + : + + + dispatch({ type: 'REMOVE_EXAM_QUESTIONS', payload: course }) + + + } + + /> + {/* */} + + +
+ ) + ) + } + {/* */}
- +