Skip to content

Commit 25e1ef9

Browse files
committed
update rooms list
1 parent 8122cc4 commit 25e1ef9

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

website/templates/rooms_list.html

+3-27
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,12 @@ <h2 class="text-2xl font-bold text-gray-900">Create Room</h2>
352352
chatSocket = new WebSocket(`${protocol}${window.location.host}/ws/discussion-rooms/chat/${roomId}/`);
353353

354354
chatSocket.onopen = function() {
355-
console.log('WebSocket connected');
356355
isConnecting = false;
357356
reconnectAttempts = 0;
358357
updateConnectionStatus(true);
359358
};
360359

361360
chatSocket.onclose = function(e) {
362-
console.log('WebSocket closed. Attempting to reconnect...');
363361
isConnecting = false;
364362
updateConnectionStatus(false);
365363

@@ -370,12 +368,10 @@ <h2 class="text-2xl font-bold text-gray-900">Create Room</h2>
370368
};
371369

372370
chatSocket.onerror = function(error) {
373-
console.error('WebSocket error:', error);
374371
isConnecting = false;
375372
updateConnectionStatus(false);
376373
};
377374
} catch (error) {
378-
console.error('Error creating WebSocket:', error);
379375
isConnecting = false;
380376
updateConnectionStatus(false);
381377
}
@@ -431,12 +427,10 @@ <h2 class="text-2xl font-bold text-gray-900">Create Room</h2>
431427

432428
// Fetch the latest messages to update the UI
433429
fetchRoomMessages(roomId);
434-
} else {
435-
console.error('Error sending message:', data.error);
436430
}
437431
})
438432
.catch(error => {
439-
console.error('Error sending message:', error);
433+
// Error handling
440434
});
441435
});
442436
});
@@ -452,58 +446,42 @@ <h2 class="text-2xl font-bold text-gray-900">Create Room</h2>
452446

453447
// Fetch messages for a specific room
454448
function fetchRoomMessages(roomId) {
455-
console.log(`Fetching messages for room ${roomId}`);
456449
fetch(`/api/room-messages/${roomId}/`)
457450
.then(response => response.json())
458451
.then(data => {
459-
console.log('API response:', data);
460452
if (data.success) {
461453
updateRoomMessages(roomId, data.messages, data.count);
462-
} else {
463-
console.error('Error in API response:', data.error);
464454
}
465455
})
466456
.catch(error => {
467-
console.error('Error fetching messages:', error);
457+
// Error handling
468458
});
469459
}
470460

471461
// Update room messages in the UI
472462
function updateRoomMessages(roomId, messages, count) {
473-
console.log(`Updating UI for room ${roomId} with ${messages.length} messages`);
474463
const roomContainer = document.querySelector(`[data-room-id="${roomId}"]`);
475464
if (!roomContainer) {
476-
console.error(`Room container not found for room ID: ${roomId}`);
477465
return;
478466
}
479467

480468
// Update message count
481469
const countBadge = roomContainer.querySelector('.bg-red-100.text-red-800');
482470
if (countBadge) {
483471
countBadge.textContent = `${count} message${count !== 1 ? 's' : ''}`;
484-
console.log(`Updated count badge: ${countBadge.textContent}`);
485-
} else {
486-
console.error('Count badge element not found');
487472
}
488473

489474
// Update messages
490475
const messagesContainer = roomContainer.querySelector('.messages-container');
491476
if (!messagesContainer) {
492-
console.error('Messages container not found');
493477
return;
494478
}
495479

496-
console.log(`Clearing and updating messages container: ${messagesContainer.id}`);
497480
// Clear existing messages
498481
messagesContainer.innerHTML = '';
499482

500483
// Add messages in reverse order (newest last)
501-
if (messages.length === 0) {
502-
console.log('No messages to display');
503-
}
504-
505-
messages.reverse().forEach((message, index) => {
506-
console.log(`Creating message element ${index + 1}/${messages.length}:`, message);
484+
messages.reverse().forEach((message) => {
507485
const messageDiv = document.createElement('div');
508486
messageDiv.className = `message p-2 rounded-lg ${
509487
message.username === '{{ request.user.username }}' ? 'bg-red-50 ml-auto' : 'bg-gray-50'
@@ -516,12 +494,10 @@ <h2 class="text-2xl font-bold text-gray-900">Create Room</h2>
516494
`;
517495

518496
messagesContainer.appendChild(messageDiv);
519-
console.log('Message element added to container');
520497
});
521498

522499
// Scroll to the bottom
523500
messagesContainer.scrollTop = messagesContainer.scrollHeight;
524-
console.log('Messages container scrolled to bottom');
525501
}
526502

527503
// Get CSRF token from cookies

0 commit comments

Comments
 (0)