Making A Question Bank Exam Completed Until Picking Questions

Picking Course Done
Listing Questions Of The Course Done
main
Pedram Keshavarzi 3 years ago
parent 19e62b975b
commit 05e898b61e
  1. 80
      src/redux/reducers/exam.js
  2. 62
      src/view/addExam/components/question.js
  3. 119
      src/view/addExam/views/AddQuestionsFromBank.js
  4. 2
      src/view/addExam/views/addQuestionnaireExam.js

@ -47,9 +47,13 @@ const initialState = {
courseBank: [ courseBank: [
{ {
id: 2, id: 1,
title: 'ریاضی' title: 'ریاضی'
} },
{
id: 2,
title: 'شیمی'
},
], ],
questionBank: [ questionBank: [
{ {
@ -80,7 +84,66 @@ const initialState = {
isAnswer: false isAnswer: false
}, },
] ]
} },
{
questionId: 2,
courseId: 2,
title:'asdaw dsfsdfiermc',
answeredPercentage: '83%',
score: 1,
options: [
{
id: 1,
title:'asdasd',
isAnswer: false
},
{
id: 2,
title:'asdasd2',
isAnswer: false
},
{
id: 3,
title:'asdasd3',
isAnswer: true
},
{
id: 4,
title:'asdasd4',
isAnswer: false
},
]
},
{
questionId: 3,
courseId: 1,
title:'asdaw dsfsdfiermc',
answeredPercentage: '43%',
score: 1,
options: [
{
id: 1,
title:'asdasd',
isAnswer: false
},
{
id: 2,
title:'asdasd2',
isAnswer: false
},
{
id: 3,
title:'asdasd3',
isAnswer: true
},
{
id: 4,
title:'asdasd4',
isAnswer: false
},
]
},
], ],
courses: [ courses: [
@ -143,6 +206,17 @@ export default function addExamReduser(state = initialState, { type, payload })
] ]
} }
case 'ADD_EXAM_COURSE':
return {
...state,
courses: [...state.courses, payload]
}
case 'REMOVE_EXAM_COURSE':
return {
...state,
courses: state.courses.filter(itm => itm.id !== payload.id)
}
default: default:
return state; return state;

@ -3,37 +3,37 @@ import React from 'react';
const Question = () => { const Question = ({data}) => {
const data = { // const data = {
questionId: 1, // questionId: 1,
courseId: 2, // courseId: 2,
title:'آیا به نظر شما این کار کار درستی است؟', // title:'آیا به نظر شما این کار کار درستی است؟',
answeredPercentage: '13', // answeredPercentage: '13',
score: 1, // score: 1,
options: [ // options: [
{ // {
id: 1, // id: 1,
title:'بله', // title:'بله',
isAnswer: false // isAnswer: false
}, // },
{ // {
id: 2, // id: 2,
title:'نظر خاصی ندارم', // title:'نظر خاصی ندارم',
isAnswer: false // isAnswer: false
}, // },
{ // {
id: 3, // id: 3,
title:'خیر', // title:'خیر',
isAnswer: true // isAnswer: true
}, // },
{ // {
id: 4, // id: 4,
title:'هویج و گوجه فرنگی؟', // title:'هویج و گوجه فرنگی؟',
isAnswer: false // isAnswer: false
}, // },
] // ]
}; // };
const gozine = [ const gozine = [
'الف', 'الف',
'ب', 'ب',
@ -43,7 +43,7 @@ const Question = () => {
'ز', 'ز',
] ]
return( return(
<div className='w-full flex flex-col justify-between items-center'> <div className='w-full flex flex-col mt-4 mb-2 justify-between items-center'>
<div className='w-4/5 flex flex-col bg-white rounded-xl border border-gray-300'> <div className='w-4/5 flex flex-col bg-white rounded-xl border border-gray-300'>
<div className='w-full border-b border-gray-300 p-4 text-gray-800 text-right'> <div className='w-full border-b border-gray-300 p-4 text-gray-800 text-right'>
{data.title} {data.title}

@ -23,26 +23,18 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
}); });
const [showCoursesInList, setShowCoursesInList] = useState([]); const [showCoursesInList, setShowCoursesInList] = useState([]);
const [choosedQuestionaries, seChoosedQuestionaries] = useState([]); const [choosedQuestionaries, seChoosedQuestionaries] = useState([]);
const [selectedQuestionare, setSelectedQuestionare] = useState({ const [selectedCourse, setSelectedCourse] = useState({
id: null, id: null,
courses: [] title: ''
}); });
const [answers, setAnswers] = useState(null); const [answers, setAnswers] = useState(null);
const [newCourse, setNewCourse] = useState({ const [newCourse, setNewCourse] = useState({
id: addExamState.questionairesCourses.length + 1, id: addExamState.questionairesCourses.length + 1,
questionnaireId: selectedQuestionare.id, questionnaireId: selectedCourse.id,
questionsQuantity:20, questionsQuantity:20,
name: '', name: '',
coefficient: 4 coefficient: 4
}) })
const [selectedCourse, setSelectedCourse] = useState({
sortId: 1,
title: 'ادبیات فارسی',
coefficient: 3,
questionStart: 1,
questionEnd: 0,
})
// console.log(choosedQuestionaries) // console.log(choosedQuestionaries)
// console.log(newQuestionaire) // console.log(newQuestionaire)
// console.log(addExamState.questionnaires) // console.log(addExamState.questionnaires)
@ -86,43 +78,31 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
<h1 className="w-full text-right text-lg text-red52 font-bold pt-4"> <h1 className="w-full text-right text-lg text-red52 font-bold pt-4">
افزودن دفترچه افزودن دفترچه
</h1> </h1>
<div className="w-full flex items-center flex-col mt-6 px-2 ">
<div className="flex justify-between w-full">
<input type='text' placeholder="نام دفترچه..." className="w-4/5 p-4 ml-2 rounded border border-red52 h-12 text-red26 outline-none"
onChange={e => setNewQuestionaire({...newQuestionaire, name: e.target.value})} />
<input type="file" placeholder="آپلود فایل دفترچه" className="bg-white items-center flex h-12 text-red26 outline-none"
/>
</div>
<div className="flex w-full justify-end pt-2">
<button className="px-6 py-2 rounded-md bg-red52 text-white font-bold"
onClick={() => {dispatch({type: 'ADD_EXAM_QUESTIONAIRES', payload: newQuestionaire}); setQuestionairePopUp(false) }}
>
تایید
</button>
</div>
{/* { {
questoinaresLists.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 ?
seChoosedQuestionaries([...choosedQuestionaries, item]) dispatch({type: 'ADD_EXAM_COURSE', payload: item})
: :
seChoosedQuestionaries(choosedQuestionaries.filter(itm => itm.id !== item.id)) 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];
@ -130,46 +110,28 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
setShowCoursesInList(newArray) setShowCoursesInList(newArray)
}}>نمایش دروس</p> }}>نمایش دروس</p> */}
</div> </div>
{
showCoursesInList[index] && <div className="w-full flex flex-col">
{
item.courses.map((course) => (
<div className="w-full flex items-center text-right px-8 py-1 border-b border-gray-100" key={`COURSE_IN_LIST__${course.sortId}`}>
<p className="w-1/3">
{course.title}
</p>
<p className="w-1/3">
ضریب : {course.coefficient}
</p>
<p
className="w-1/3"
>از سوال {course.questionStart} تا سوال {course.questionEnd}</p>
</div>
))
}
</div>
}
</> </>
) )
) )
} */} }
</div>
</div>
</div>
</div> </div>
} }
{ {
addCoursePopup && // addCoursePopup &&
<AddQuestionnaireCourse // <AddQuestionnaireCourse
closeOnClick={() => setAddCoursePopup(false)} // closeOnClick={() => setAddCoursePopup(false)}
nameOnChange={e => setNewCourse({...newCourse, name: e.target.value})} // nameOnChange={e => setNewCourse({...newCourse, name: e.target.value})}
coefficientOnChange={e => setNewCourse({...newCourse, coefficient: e.target.vlaue})} // coefficientOnChange={e => setNewCourse({...newCourse, coefficient: e.target.vlaue})}
questionQuantityOnChange={e => setNewCourse({...newCourse, questionsQuantity: e.target.value, questionnaireId: selectedQuestionare.id})} // questionQuantityOnChange={e => setNewCourse({...newCourse, questionsQuantity: e.target.value, questionnaireId: selectedQuestionare.id})}
submitOnClick={() => {dispatch({type: 'ADD_QUESTIONNAIRE_COURSES', payload : newCourse}); setAddCoursePopup(false); setFakeState(fakeState + 356)} } // submitOnClick={() => {dispatch({type: 'ADD_QUESTIONNAIRE_COURSES', payload : newCourse}); setAddCoursePopup(false); setFakeState(fakeState + 356)} }
/> // />
} }
@ -183,27 +145,30 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
</div> </div>
<div className="w-5/6 flex flex-row"> <div className="w-5/6 flex flex-row">
{ {addExamState.courses.length > 0 &&
addExamState.questionnaires.map( addExamState.courses.map(
(item => ( (item => (
<div className={`flex flex-col ${selectedQuestionare.id === item.id ? 'bg-pinkF5 border border-red52 text-red52' : 'bg-white border border-gray-300 text-blue3A'} items-center justify-center 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={() => setSelectedQuestionare({id : item.id,name: item.name, courses: addExamState.questionairesCourses.filter(itm => itm.questionnaireId == item.id)})} onClick={() => setSelectedCourse(item)}
> >
<p className="w-full text-left px-4" onClick={() => dispatch({type: 'REMOVE_EXAM_COURSE', payload: item})}>
x
</p>
<p className="text-red52"> <p className="text-red52">
دفترچه {item.name} {item.title}
</p> </p>
</div> </div>
)) ))
) )
} }
<div className="flex flex-col bg-white items-center justify-center w-36 h-32 mx-2 font-bold border border-gray-300 text-blue3A rounded-xl cursor-pointer" onClick={() => addExamState.type == 'bank' ? console.log('bank') : setQuestionairePopUp(true)}> <div className="flex flex-col bg-white items-center justify-center w-36 h-32 mx-2 font-bold border border-gray-300 text-blue3A rounded-xl cursor-pointer" onClick={() => setQuestionairePopUp(true)}>
<p className="" style={{ fontSize: '40px' }}> <p className="" style={{ fontSize: '40px' }}>
+ +
</p> </p>
<p className=""> <p className="">
{addExamState.type == 'bank' ? 'افزودن درس' : 'افزودن دفترچه'} افزودن درس
</p> </p>
</div> </div>
@ -214,7 +179,7 @@ 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 && (<> selectedQuestionare.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} دفترچه {selectedQuestionare.name}
@ -239,14 +204,18 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
<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)}>
افزودن درس افزودن درس
</button> </button>
</div>} </div>} */}
</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 &&
<Question /> addExamState.questionBank.filter(itm => itm.courseId == selectedCourse.id).map(
(course) => (<Question data={course} />)
)
}
{/* <Question /> */}
</div> </div>
</div> </div>

@ -274,4 +274,4 @@ const mapStateToProps = (state) => ({
addExamState: state.addExamReduser addExamState: state.addExamReduser
}) })
export default connect(mapStateToProps)(AddQuestionnaireExam); export default connect(mapStateToProps)(AddQuestionnaireCourse);
Loading…
Cancel
Save