|
3137 | 3137 | count: parseInt(document.getElementById('ai-count').value), |
3138 | 3138 | }); |
3139 | 3139 | if (res.error) throw new Error(res.error); |
3140 | | - renderGeneratedQuestions(res.questions); |
| 3140 | + // Append to existing questions instead of replacing |
| 3141 | + const existing = window.generatedQuestions || []; |
| 3142 | + renderGeneratedQuestions([...existing, ...res.questions]); |
3141 | 3143 | } catch (e) { |
3142 | 3144 | document.getElementById('generated-questions').innerHTML = `<div class="p-4 bg-red-50 text-red-600 rounded-lg">${e.message}</div>`; |
3143 | 3145 | } finally { |
|
3157 | 3159 | }; |
3158 | 3160 |
|
3159 | 3161 | const courseSelected = document.getElementById('ai-course').value; |
3160 | | - const addAllBtn = courseSelected ? ` |
3161 | | - <div class="mb-4 flex justify-end"> |
| 3162 | + const headerBtns = ` |
| 3163 | + <div class="mb-4 flex justify-between items-center"> |
| 3164 | + <button onclick="clearGeneratedQuestions()" class="text-sm text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-200 flex items-center gap-1"> |
| 3165 | + <i data-lucide="trash-2" class="w-4 h-4"></i> |
| 3166 | + Clear All |
| 3167 | + </button> |
| 3168 | + ${courseSelected ? ` |
3162 | 3169 | <button onclick="addAllGeneratedQuestions()" id="add-all-btn" class="btn-primary px-4 py-2 text-white rounded-lg text-sm font-medium flex items-center gap-2"> |
3163 | 3170 | <i data-lucide="plus-circle" class="w-4 h-4"></i> |
3164 | 3171 | Add All ${questions.length} Questions |
3165 | 3172 | </button> |
| 3173 | + ` : '<span class="text-sm text-gray-400">Select a course to add questions</span>'} |
3166 | 3174 | </div> |
3167 | | - ` : ''; |
| 3175 | + `; |
3168 | 3176 |
|
3169 | | - document.getElementById('generated-questions').innerHTML = addAllBtn + questions.map((q, i) => { |
| 3177 | + document.getElementById('generated-questions').innerHTML = headerBtns + questions.map((q, i) => { |
3170 | 3178 | const qType = q.question_type || document.getElementById('ai-type').value; |
3171 | 3179 | const typeLabel = formatType(qType); |
3172 | 3180 | const typeClass = typeColors[qType] || 'bg-purple-100 text-purple-700'; |
|
3191 | 3199 | lucide.createIcons(); |
3192 | 3200 | } |
3193 | 3201 |
|
| 3202 | + function clearGeneratedQuestions() { |
| 3203 | + window.generatedQuestions = []; |
| 3204 | + document.getElementById('generated-questions').innerHTML = '<p class="text-gray-400 dark:text-slate-500 text-sm">Questions will appear here after generation</p>'; |
| 3205 | + } |
| 3206 | + |
3194 | 3207 | async function addAllGeneratedQuestions() { |
3195 | 3208 | const courseCode = document.getElementById('ai-course').value; |
3196 | 3209 | const tagName = document.getElementById('ai-tag').value; |
|
0 commit comments