|
| 1 | +import { useState } from 'react'; |
| 2 | +import '../Styles/AssignmentCreate.css'; |
| 3 | + |
| 4 | +const AssignmentCreate = () => { |
| 5 | + const [view, setView] = useState('list'); |
| 6 | + const [selectedAssignment, setSelectedAssignment] = useState(null); |
| 7 | + // const [selectedQuizId, setSelectedQuizId] = useState(1); // Mock quiz ID |
| 8 | + const [questionType, setQuestionType] = useState('MC'); |
| 9 | + const [choices, setChoices] = useState([{ text: '', isCorrect: false }]); |
| 10 | + |
| 11 | + const assignments = [ |
| 12 | + { id: 1, title: 'Math Homework', type: 'HW', deadline: '2025-04-30' }, |
| 13 | + { id: 2, title: 'Science Quiz', type: 'QZ', deadline: '2025-05-05' } |
| 14 | + ]; |
| 15 | + |
| 16 | + const questions = [ |
| 17 | + { id: 1, type: 'MC', text: 'What is 2 + 2?', points: 1, solution: 4 }, |
| 18 | + { id: 2, type: 'SA', text: 'Define gravity.', points: 2, solution: 'Ask Newton' }, |
| 19 | + ]; |
| 20 | + |
| 21 | + const handleAddChoice = () => { |
| 22 | + setChoices([...choices, { text: '', isCorrect: false }]); |
| 23 | + }; |
| 24 | + |
| 25 | + return ( |
| 26 | + <div className="assignment-create_container"> |
| 27 | + {view === 'list' && ( |
| 28 | + <> |
| 29 | + <h1 className="assignment-create_header">Assignments</h1> |
| 30 | + <div className="assignment-create_button-container"> |
| 31 | + <button |
| 32 | + className="assignment-create_button" |
| 33 | + onClick={() => { |
| 34 | + setSelectedAssignment(null); |
| 35 | + setView('create'); |
| 36 | + }} |
| 37 | + > |
| 38 | + Create New Assignment |
| 39 | + </button> |
| 40 | + </div> |
| 41 | + <table className="assignment-create_table"> |
| 42 | + <thead> |
| 43 | + <tr> |
| 44 | + <th className="assignment-create_label">ID</th> |
| 45 | + <th className="assignment-create_label">Title</th> |
| 46 | + <th className="assignment-create_label">Type</th> |
| 47 | + <th className="assignment-create_label">Deadline</th> |
| 48 | + <th className="assignment-create_label">Actions</th> |
| 49 | + </tr> |
| 50 | + </thead> |
| 51 | + <tbody> |
| 52 | + {assignments.map((a) => ( |
| 53 | + <tr key={a.id}> |
| 54 | + <td className="assignment-create_cell">{a.id}</td> |
| 55 | + <td className="assignment-create_cell">{a.title}</td> |
| 56 | + <td className="assignment-create_cell">{a.type}</td> |
| 57 | + <td className="assignment-create_cell">{a.deadline}</td> |
| 58 | + <td className="assignment-create_cell"> |
| 59 | + <button |
| 60 | + className="assignment-create_link" |
| 61 | + onClick={() => { |
| 62 | + setSelectedAssignment(a); |
| 63 | + setView('create'); |
| 64 | + }} |
| 65 | + > |
| 66 | + Edit |
| 67 | + </button> |
| 68 | + <button |
| 69 | + className="assignment-create_link" |
| 70 | + onClick={() => setView('quiz')} |
| 71 | + > |
| 72 | + View Quiz |
| 73 | + </button> |
| 74 | + </td> |
| 75 | + </tr> |
| 76 | + ))} |
| 77 | + </tbody> |
| 78 | + </table> |
| 79 | + </> |
| 80 | + )} |
| 81 | + |
| 82 | + {(view === 'create' || view === 'edit') && ( |
| 83 | + <div className="assignment-create_form"> |
| 84 | + <h2 className="assignment-create_header"> |
| 85 | + {selectedAssignment ? 'Edit Assignment' : 'Create Assignment'} |
| 86 | + </h2> |
| 87 | + <form> |
| 88 | + <input |
| 89 | + type="text" |
| 90 | + placeholder="Title" |
| 91 | + className="assignment-create_input" |
| 92 | + defaultValue={selectedAssignment?.title || ''} |
| 93 | + /> |
| 94 | + <textarea |
| 95 | + placeholder="Description" |
| 96 | + className="assignment-create_input" |
| 97 | + /> |
| 98 | + <select |
| 99 | + className="assignment-create_input" |
| 100 | + defaultValue={selectedAssignment?.type || 'HW'} |
| 101 | + > |
| 102 | + <option value="EX">Exercises</option> |
| 103 | + <option value="HW">Homework</option> |
| 104 | + <option value="QZ">Quiz</option> |
| 105 | + <option value="TT">Test</option> |
| 106 | + <option value="EC">Extra Credit</option> |
| 107 | + </select> |
| 108 | + <input type="datetime-local" className="assignment-create_input" /> |
| 109 | + <input type="file" className="assignment-create_input" /> |
| 110 | + <input |
| 111 | + type="number" |
| 112 | + placeholder="Student ID (optional)" |
| 113 | + className="assignment-create_input" |
| 114 | + /> |
| 115 | + <div className="assignment-create_button-container"> |
| 116 | + <button className="assignment-create_button" type="submit"> |
| 117 | + Submit |
| 118 | + </button> |
| 119 | + <button |
| 120 | + className="assignment-create_button" |
| 121 | + type="button" |
| 122 | + onClick={() => setView('list')} |
| 123 | + > |
| 124 | + Cancel |
| 125 | + </button> |
| 126 | + </div> |
| 127 | + </form> |
| 128 | + </div> |
| 129 | + )} |
| 130 | + |
| 131 | + {view === 'quiz' && ( |
| 132 | + <> |
| 133 | + <h2 className="assignment-create_header">Quiz Questions</h2> |
| 134 | + <div className="assignment-create_button-container"> |
| 135 | + <button |
| 136 | + className="assignment-create_button" |
| 137 | + onClick={() => setView('question')} |
| 138 | + > |
| 139 | + Add Question |
| 140 | + </button> |
| 141 | + </div> |
| 142 | + <table className="assignment-create_table"> |
| 143 | + <thead> |
| 144 | + <tr> |
| 145 | + <th className="assignment-create_label">#</th> |
| 146 | + <th className="assignment-create_label">Type</th> |
| 147 | + <th className="assignment-create_label">Points</th> |
| 148 | + <th className="assignment-create_label">Question</th> |
| 149 | + <th className="assignment-create_label">Solution</th> |
| 150 | + </tr> |
| 151 | + </thead> |
| 152 | + <tbody> |
| 153 | + {questions.map((q) => ( |
| 154 | + <tr key={q.id}> |
| 155 | + <td className="assignment-create_cell">{q.id}</td> |
| 156 | + <td className="assignment-create_cell">{q.type}</td> |
| 157 | + <td className="assignment-create_cell">{q.points}</td> |
| 158 | + <td className="assignment-create_cell">{q.text}</td> |
| 159 | + <td className="assignment-create_cell">{q.solution}</td> |
| 160 | + </tr> |
| 161 | + ))} |
| 162 | + </tbody> |
| 163 | + </table> |
| 164 | + </> |
| 165 | + )} |
| 166 | + |
| 167 | + {view === 'question' && ( |
| 168 | + <div className="assignment-create_form"> |
| 169 | + <h2 className="assignment-create_header">Create Question</h2> |
| 170 | + <form> |
| 171 | + <select |
| 172 | + className="assignment-create_input" |
| 173 | + value={questionType} |
| 174 | + onChange={(e) => setQuestionType(e.target.value)} |
| 175 | + > |
| 176 | + <option value="MC">Multiple Choice</option> |
| 177 | + <option value="SA">Short Answer</option> |
| 178 | + </select> |
| 179 | + <input type="number" placeholder="Order" className="assignment-create_input" /> |
| 180 | + <textarea placeholder="Question Text" className="assignment-create_input" /> |
| 181 | + <input type="number" placeholder="Points" className="assignment-create_input" /> |
| 182 | + |
| 183 | + {questionType === 'MC' && ( |
| 184 | + <> |
| 185 | + <h4 style={{ marginTop: '20px' }}>Choices</h4> |
| 186 | + {choices.map((choice, index) => ( |
| 187 | + <div |
| 188 | + key={index} |
| 189 | + className="assignment-create_input" |
| 190 | + style={{ |
| 191 | + display: 'flex', |
| 192 | + gap: '10px', |
| 193 | + marginBottom: '10px', |
| 194 | + }} |
| 195 | + > |
| 196 | + <input |
| 197 | + type="text" |
| 198 | + placeholder={`Choice ${index + 1}`} |
| 199 | + value={choice.text} |
| 200 | + onChange={(e) => { |
| 201 | + const newChoices = [...choices]; |
| 202 | + newChoices[index].text = e.target.value; |
| 203 | + setChoices(newChoices); |
| 204 | + }} |
| 205 | + /> |
| 206 | + <label> |
| 207 | + <input |
| 208 | + type="checkbox" |
| 209 | + checked={choice.isCorrect} |
| 210 | + onChange={(e) => { |
| 211 | + const newChoices = [...choices]; |
| 212 | + newChoices[index].isCorrect = e.target.checked; |
| 213 | + setChoices(newChoices); |
| 214 | + }} |
| 215 | + /> |
| 216 | + Correct |
| 217 | + </label> |
| 218 | + </div> |
| 219 | + ))} |
| 220 | + </> |
| 221 | + )} |
| 222 | + |
| 223 | + <div className="assignment-create_button-container"> |
| 224 | + <button |
| 225 | + type="button" |
| 226 | + className="assignment-create_button" |
| 227 | + onClick={handleAddChoice} |
| 228 | + > |
| 229 | + Add Another Choice |
| 230 | + </button> |
| 231 | + <button className="assignment-create_button" type="submit"> |
| 232 | + Submit |
| 233 | + </button> |
| 234 | + <button |
| 235 | + className="assignment-create_button" |
| 236 | + type="button" |
| 237 | + onClick={() => setView('quiz')} |
| 238 | + > |
| 239 | + Cancel |
| 240 | + </button> |
| 241 | + </div> |
| 242 | + </form> |
| 243 | + </div> |
| 244 | + )} |
| 245 | + </div> |
| 246 | + ); |
| 247 | +}; |
| 248 | + |
| 249 | +export default AssignmentCreate; |
0 commit comments