Skip to content

Commit 6426251

Browse files
jsb2092claude
andcommitted
Add append mode for AI question generation
- New questions now append to existing ones instead of replacing - Added "Clear All" button to start fresh - Shows helpful message when no course selected Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 525d5a8 commit 6426251

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

questionbank/static/js/app.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,7 +3137,9 @@
31373137
count: parseInt(document.getElementById('ai-count').value),
31383138
});
31393139
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]);
31413143
} catch (e) {
31423144
document.getElementById('generated-questions').innerHTML = `<div class="p-4 bg-red-50 text-red-600 rounded-lg">${e.message}</div>`;
31433145
} finally {
@@ -3157,16 +3159,22 @@
31573159
};
31583160

31593161
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 ? `
31623169
<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">
31633170
<i data-lucide="plus-circle" class="w-4 h-4"></i>
31643171
Add All ${questions.length} Questions
31653172
</button>
3173+
` : '<span class="text-sm text-gray-400">Select a course to add questions</span>'}
31663174
</div>
3167-
` : '';
3175+
`;
31683176

3169-
document.getElementById('generated-questions').innerHTML = addAllBtn + questions.map((q, i) => {
3177+
document.getElementById('generated-questions').innerHTML = headerBtns + questions.map((q, i) => {
31703178
const qType = q.question_type || document.getElementById('ai-type').value;
31713179
const typeLabel = formatType(qType);
31723180
const typeClass = typeColors[qType] || 'bg-purple-100 text-purple-700';
@@ -3191,6 +3199,11 @@
31913199
lucide.createIcons();
31923200
}
31933201

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+
31943207
async function addAllGeneratedQuestions() {
31953208
const courseCode = document.getElementById('ai-course').value;
31963209
const tagName = document.getElementById('ai-tag').value;

0 commit comments

Comments
 (0)