Adding Questions Done

main
Pedram Keshavarzi 3 years ago
parent 2f54137fa6
commit b36bc037d3
  1. 23
      src/redux/reducers/exam.js
  2. 114
      src/view/addExam/views/AddQuestionsFromBank.js

@ -175,16 +175,7 @@ export default function addExamReduser(state = initialState, { type, payload })
description: payload.description, description: payload.description,
type: payload.type 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': case 'ADD_EXAM_QUESTIONAIRES':
return { return {
...state, ...state,
@ -217,6 +208,18 @@ export default function addExamReduser(state = initialState, { type, payload })
courses: state.courses.filter(itm => itm.id !== payload.id) 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: default:
return state; return state;

@ -31,7 +31,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
const [newCourse, setNewCourse] = useState({ const [newCourse, setNewCourse] = useState({
id: addExamState.questionairesCourses.length + 1, id: addExamState.questionairesCourses.length + 1,
questionnaireId: selectedCourse.id, questionnaireId: selectedCourse.id,
questionsQuantity:20, questionsQuantity: 20,
name: '', name: '',
coefficient: 4 coefficient: 4
}) })
@ -48,8 +48,8 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
useEffect(() => { useEffect(() => {
// questoinaresLists.map(item => showCoursesInList.push(false)); // questoinaresLists.map(item => showCoursesInList.push(false));
if(answers !== null && answers !== []) { if (answers !== null && answers !== []) {
answers.map(item => dispatch({type: 'ADD_ANSWERS', payload : item})) answers.map(item => dispatch({ type: 'ADD_ANSWERS', payload: item }))
} }
}, [answers]) }, [answers])
@ -81,28 +81,28 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
{ {
addExamState.courseBank.map( addExamState.courseBank.map(
(item, index) => ( (item, index) => (
<> <>
<div className="w-full flex items-center py-2 justify-between border-b pl-8 border-gray-300"> <div className="w-full flex items-center py-2 justify-between border-b pl-8 border-gray-300">
<Checkbox name={`PICK_QUESTIONARE_${index}`} <Checkbox name={`PICK_QUESTIONARE_${index}`}
onChange={(e) => onChange={(e) =>
e.target.checked ? e.target.checked ?
dispatch({type: 'ADD_EXAM_COURSE', payload: item}) dispatch({ type: 'ADD_EXAM_COURSE', payload: item })
: :
dispatch({type: 'REMOVE_EXAM_COURSE', payload: item}) dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item })
} }
/> />
<h2 className="text-red26 font-bold">{item.title}</h2> <h2 className="text-red26 font-bold">{item.title}</h2>
{/* <h4>تعداد سوالات: {item.numberOfQuestions}</h4> {/* <h4>تعداد سوالات: {item.numberOfQuestions}</h4>
<p>تعداد دروس: {item.courses.length}</p> */} <p>تعداد دروس: {item.courses.length}</p> */}
{/* <p className="cursor-pointer" onClick={() => { {/* <p className="cursor-pointer" onClick={() => {
let newArray = [...showCoursesInList]; let newArray = [...showCoursesInList];
newArray[index] = !newArray[index]; newArray[index] = !newArray[index];
@ -112,13 +112,13 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
}}>نمایش دروس</p> */} }}>نمایش دروس</p> */}
</div> </div>
</> </>
)
) )
} )
</div> }
</div>
</div> </div>
@ -149,16 +149,16 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
addExamState.courses.map( addExamState.courses.map(
(item => ( (item => (
<div className={`flex flex-col ${selectedCourse.id === item.id ? 'bg-pinkF5 border border-red52 text-red52' : 'bg-white border border-gray-300 text-blue3A'} items-center justify-between pb-12 pt-2 w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`} <div className={`flex flex-col ${selectedCourse.id === item.id ? 'bg-pinkF5 border border-red52 text-red52' : 'bg-white border border-gray-300 text-blue3A'} items-center justify-between pb-12 pt-2 w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`}
onClick={() => setSelectedCourse(item)} onClick={() => setSelectedCourse(item)}
> >
<p className="w-full text-left px-4" onClick={() => dispatch({type: 'REMOVE_EXAM_COURSE', payload: item})}> <p className="w-full text-left px-4" onClick={() => dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item })}>
x x
</p> </p>
<p className="text-red52"> <p className="text-red52">
{item.title} {item.title}
</p> </p>
</div> </div>
)) ))
) )
} }
@ -168,7 +168,7 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
+ +
</p> </p>
<p className=""> <p className="">
افزودن درس افزودن درس
</p> </p>
</div> </div>
@ -179,27 +179,28 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
<div className="w-full flex px-10"> <div className="w-full flex px-10">
<div className="w-1/2 border-l flex flex-col border-gray-300 py-10"> <div className="w-1/2 border-l flex flex-col border-gray-300 py-10">
{/* { {
selectedQuestionare.id !== null && (<> selectedCourse.id !== null && (<>
<h1 className="text-blue3A w-full font-bold text-lg text-right"> <h1 className="text-blue3A w-full font-bold text-lg text-right">
دفترچه {selectedQuestionare.name} {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 overflow-x-hidden overflow-scroll" style={{height: '500px'}}>
<div className="w-4/5 "> <div className="w-4/5 ">
{ {
addExamState.questionairesCourses.filter(itm => itm.questionnaireId == selectedQuestionare.id).map( addExamState.questions.filter(itm => itm.courseId == selectedCourse.id).map(
(item) => ( (item) => (
<SelectedCourse title={item.name} coefficient={item.coefficient} questionQuantity={item.questionsQuantity} <Question data={item} />
onClick={() => {setSelectedCourse(item); console.log(selectedCourse)}}/>
) )
) )
} }
</div> </div>
</div> </div>
</>) </>)
} }
{selectedQuestionare.id !== null && {/* {selectedQuestionare.id !== null &&
<div className="w-full flex justify-center mt-10"> <div className="w-full flex justify-center mt-10">
<button className=" bg-gray-300 text-xl text-gray-500 border-gray-500 w-1/3 h-12 rounded-xl border" onClick={() => setAddCoursePopup(true)}> <button className=" bg-gray-300 text-xl text-gray-500 border-gray-500 w-1/3 h-12 rounded-xl border" onClick={() => setAddCoursePopup(true)}>
افزودن درس افزودن درس
@ -208,14 +209,35 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
</div> </div>
<div className="w-1/2 flex justify-center"> <div className="w-1/2 flex justify-center">
<div className="w-4/5 py-8"> <div className="w-4/5 py-8">
{/* <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) => (<Question data={course} />) (course , index) => (
)
} <div className="flex items-start justify-between w-full">
{/* <Question /> */} <Checkbox name={`PICK_QUESTIONS_${index}_${course.courseId}`}
onChange={(e) =>
e.target.checked ?
dispatch({ type: 'ADD_EXAM_QUESTIONS', payload: course })
// console.log('asodjasd')
:
dispatch({ type: 'REMOVE_EXAM_QUESTIONS', payload: course })
}
/>
{/* <button onClick={() => dispatch({ type: 'ADD_EXAM_QUESTIONS', payload: course })}>ادد کردن</button> */}
<Question data={course} />
</div>
)
)
}
{/* <Question /> */}
</div> </div>
</div> </div>

Loading…
Cancel
Save