Spaces:
Running
Running
Upload 10 files
Browse files- src/views/InstructorView.js +90 -2
src/views/InstructorView.js
CHANGED
|
@@ -373,6 +373,7 @@ export async function renderInstructorView() {
|
|
| 373 |
}
|
| 374 |
|
| 375 |
export function setupInstructorEvents() {
|
|
|
|
| 376 |
// Utility for cleaning prompt indentation
|
| 377 |
// Utility for cleaning prompt indentation
|
| 378 |
// Utility for cleaning text for display
|
|
@@ -534,6 +535,94 @@ export function setupInstructorEvents() {
|
|
| 534 |
renderTransposedHeatmap(users);
|
| 535 |
}
|
| 536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
let roomUnsubscribe = null;
|
| 538 |
let currentInstructor = null;
|
| 539 |
|
|
@@ -758,8 +847,7 @@ export function setupInstructorEvents() {
|
|
| 758 |
}
|
| 759 |
|
| 760 |
// Create Room
|
| 761 |
-
|
| 762 |
-
// Create Room
|
| 763 |
if (createBtn) {
|
| 764 |
createBtn.addEventListener('click', async () => {
|
| 765 |
// 4-Digit Room Code
|
|
|
|
| 373 |
}
|
| 374 |
|
| 375 |
export function setupInstructorEvents() {
|
| 376 |
+
console.log("Starting setupInstructorEvents...");
|
| 377 |
// Utility for cleaning prompt indentation
|
| 378 |
// Utility for cleaning prompt indentation
|
| 379 |
// Utility for cleaning text for display
|
|
|
|
| 535 |
renderTransposedHeatmap(users);
|
| 536 |
}
|
| 537 |
|
| 538 |
+
// --- Broadcast Modal & Reject Logic ---
|
| 539 |
+
window.showBroadcastModal = (userId, challengeId) => {
|
| 540 |
+
const student = currentStudents.find(u => u.id === userId);
|
| 541 |
+
if (!student) return;
|
| 542 |
+
|
| 543 |
+
const p = student.progress?.[challengeId];
|
| 544 |
+
if (!p) return;
|
| 545 |
+
|
| 546 |
+
const challenge = cachedChallenges.find(c => c.id === challengeId);
|
| 547 |
+
const title = challenge ? challenge.title : 'Unknown Challenge';
|
| 548 |
+
|
| 549 |
+
const modal = document.getElementById('broadcast-modal');
|
| 550 |
+
const content = document.getElementById('broadcast-content');
|
| 551 |
+
if (!modal || !content) return;
|
| 552 |
+
|
| 553 |
+
const avatarEl = document.getElementById('broadcast-avatar');
|
| 554 |
+
if (avatarEl) avatarEl.textContent = student.nickname[0] || '?';
|
| 555 |
+
|
| 556 |
+
const authorEl = document.getElementById('broadcast-author');
|
| 557 |
+
if (authorEl) authorEl.textContent = student.nickname;
|
| 558 |
+
|
| 559 |
+
const challengeEl = document.getElementById('broadcast-challenge');
|
| 560 |
+
if (challengeEl) challengeEl.textContent = title;
|
| 561 |
+
|
| 562 |
+
const rawText = p.prompt || p.code || '';
|
| 563 |
+
const isCode = !p.prompt && !!p.code;
|
| 564 |
+
const promptContainer = document.getElementById('broadcast-prompt');
|
| 565 |
+
if (promptContainer) {
|
| 566 |
+
promptContainer.textContent = cleanText(rawText, isCode);
|
| 567 |
+
promptContainer.style.textAlign = 'left';
|
| 568 |
+
promptContainer.style.whiteSpace = 'pre-wrap';
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
// Store IDs for actions
|
| 572 |
+
modal.dataset.userId = userId;
|
| 573 |
+
modal.dataset.challengeId = challengeId;
|
| 574 |
+
|
| 575 |
+
modal.classList.remove('hidden');
|
| 576 |
+
setTimeout(() => {
|
| 577 |
+
content.classList.remove('scale-95', 'opacity-0');
|
| 578 |
+
content.classList.add('opacity-100', 'scale-100');
|
| 579 |
+
}, 10);
|
| 580 |
+
};
|
| 581 |
+
|
| 582 |
+
// Close Modal Logic (Global helper)
|
| 583 |
+
window.closeBroadcastModal = () => {
|
| 584 |
+
const modal = document.getElementById('broadcast-modal');
|
| 585 |
+
const content = document.getElementById('broadcast-content');
|
| 586 |
+
if (modal && content) {
|
| 587 |
+
content.classList.remove('opacity-100', 'scale-100');
|
| 588 |
+
content.classList.add('scale-95', 'opacity-0');
|
| 589 |
+
setTimeout(() => {
|
| 590 |
+
modal.classList.add('hidden');
|
| 591 |
+
}, 200);
|
| 592 |
+
}
|
| 593 |
+
};
|
| 594 |
+
|
| 595 |
+
// Bind Reject Button Logic
|
| 596 |
+
const btnReject = document.getElementById('btn-reject-task');
|
| 597 |
+
if (btnReject) {
|
| 598 |
+
// Remove existing listeners to avoid duplicates (cloneNode trick)
|
| 599 |
+
const newBtn = btnReject.cloneNode(true);
|
| 600 |
+
btnReject.parentNode.replaceChild(newBtn, btnReject);
|
| 601 |
+
|
| 602 |
+
newBtn.addEventListener('click', async () => {
|
| 603 |
+
const modal = document.getElementById('broadcast-modal');
|
| 604 |
+
const userId = modal.dataset.userId;
|
| 605 |
+
const challengeId = modal.dataset.challengeId;
|
| 606 |
+
const roomCode = localStorage.getItem('vibecoding_room_code');
|
| 607 |
+
|
| 608 |
+
console.log('Reject attempt:', { userId, challengeId, roomCode });
|
| 609 |
+
|
| 610 |
+
if (!userId || !challengeId) return;
|
| 611 |
+
|
| 612 |
+
if (confirm('確定要退回此學員的進度嗎?學員將需要重新作答。')) {
|
| 613 |
+
try {
|
| 614 |
+
const { resetProgress } = await import("../services/classroom.js");
|
| 615 |
+
await resetProgress(roomCode, userId, challengeId);
|
| 616 |
+
alert('已成功退回,學員將需要重新作答。');
|
| 617 |
+
window.closeBroadcastModal();
|
| 618 |
+
} catch (e) {
|
| 619 |
+
console.error("Reject failed:", e);
|
| 620 |
+
alert('退回失敗: ' + e.message);
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
});
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
let roomUnsubscribe = null;
|
| 627 |
let currentInstructor = null;
|
| 628 |
|
|
|
|
| 847 |
}
|
| 848 |
|
| 849 |
// Create Room
|
| 850 |
+
console.log("Checking createBtn:", createBtn);
|
|
|
|
| 851 |
if (createBtn) {
|
| 852 |
createBtn.addEventListener('click', async () => {
|
| 853 |
// 4-Digit Room Code
|