Spaces:
Running
Running
Upload 9 files
Browse files- src/views/InstructorView.js +18 -5
src/views/InstructorView.js
CHANGED
|
@@ -636,6 +636,9 @@ export function setupInstructorEvents() {
|
|
| 636 |
enterRoom(savedRoomCode);
|
| 637 |
}
|
| 638 |
|
|
|
|
|
|
|
|
|
|
| 639 |
function enterRoom(roomCode) {
|
| 640 |
createContainer.classList.add('hidden');
|
| 641 |
roomInfo.classList.remove('hidden');
|
|
@@ -645,8 +648,11 @@ export function setupInstructorEvents() {
|
|
| 645 |
localStorage.setItem('vibecoding_instructor_room', roomCode);
|
| 646 |
sessionStorage.setItem('vibecoding_instructor_in_room', 'true');
|
| 647 |
|
|
|
|
|
|
|
|
|
|
| 648 |
// Subscribe to updates
|
| 649 |
-
subscribeToRoom(roomCode, (students) => {
|
| 650 |
currentStudents = students;
|
| 651 |
renderTransposedHeatmap(students);
|
| 652 |
});
|
|
@@ -655,18 +661,25 @@ export function setupInstructorEvents() {
|
|
| 655 |
// Leave Room Logic
|
| 656 |
document.getElementById('leave-room-btn').addEventListener('click', () => {
|
| 657 |
if (confirm('確定要離開目前教室嗎?(不會刪除教室資料,僅回到選擇介面)')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
// UI Reset
|
| 659 |
createContainer.classList.remove('hidden');
|
| 660 |
roomInfo.classList.add('hidden');
|
| 661 |
dashboardContent.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
|
| 663 |
// State Clear
|
| 664 |
sessionStorage.removeItem('vibecoding_instructor_in_room');
|
| 665 |
localStorage.removeItem('vibecoding_instructor_room');
|
| 666 |
-
|
| 667 |
-
// Reload to clear listeners/subscriptions effectively
|
| 668 |
-
// Or we could implement an unsubscribe, but reload is safer for quick implementation
|
| 669 |
-
window.location.reload();
|
| 670 |
}
|
| 671 |
});
|
| 672 |
|
|
|
|
| 636 |
enterRoom(savedRoomCode);
|
| 637 |
}
|
| 638 |
|
| 639 |
+
// Module-level variable to track subscription
|
| 640 |
+
let roomUnsubscribe = null;
|
| 641 |
+
|
| 642 |
function enterRoom(roomCode) {
|
| 643 |
createContainer.classList.add('hidden');
|
| 644 |
roomInfo.classList.remove('hidden');
|
|
|
|
| 648 |
localStorage.setItem('vibecoding_instructor_room', roomCode);
|
| 649 |
sessionStorage.setItem('vibecoding_instructor_in_room', 'true');
|
| 650 |
|
| 651 |
+
// Unsubscribe previous if any
|
| 652 |
+
if (roomUnsubscribe) roomUnsubscribe();
|
| 653 |
+
|
| 654 |
// Subscribe to updates
|
| 655 |
+
roomUnsubscribe = subscribeToRoom(roomCode, (students) => {
|
| 656 |
currentStudents = students;
|
| 657 |
renderTransposedHeatmap(students);
|
| 658 |
});
|
|
|
|
| 661 |
// Leave Room Logic
|
| 662 |
document.getElementById('leave-room-btn').addEventListener('click', () => {
|
| 663 |
if (confirm('確定要離開目前教室嗎?(不會刪除教室資料,僅回到選擇介面)')) {
|
| 664 |
+
// Unsubscribe
|
| 665 |
+
if (roomUnsubscribe) {
|
| 666 |
+
roomUnsubscribe();
|
| 667 |
+
roomUnsubscribe = null;
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
// UI Reset
|
| 671 |
createContainer.classList.remove('hidden');
|
| 672 |
roomInfo.classList.add('hidden');
|
| 673 |
dashboardContent.classList.add('hidden');
|
| 674 |
+
document.getElementById('group-photo-btn').classList.add('hidden'); // Hide photo button
|
| 675 |
+
|
| 676 |
+
// Clear Data Display
|
| 677 |
+
document.getElementById('heatmap-body').innerHTML = '<tr><td colspan="100" class="text-center py-10 text-gray-500">等待資料載入...</td></tr>';
|
| 678 |
+
document.getElementById('heatmap-header').innerHTML = '<th class="p-3 text-left sticky left-0 bg-gray-800 z-20 border-b border-gray-700 min-w-[150px]">學員 / 關卡</th>';
|
| 679 |
|
| 680 |
// State Clear
|
| 681 |
sessionStorage.removeItem('vibecoding_instructor_in_room');
|
| 682 |
localStorage.removeItem('vibecoding_instructor_room');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 683 |
}
|
| 684 |
});
|
| 685 |
|