Fixed bugs, and added a run script.

This commit is contained in:
SolidLiquid
2025-06-05 21:24:36 +12:00
parent 7c44f0ba56
commit 13dfcccaad
3 changed files with 34 additions and 17 deletions

View File

@@ -2,11 +2,12 @@
{% block title %}Room {{ room_code }}{% endblock %}
{% block content %}
<h1>Room {{ room_code }}</h1>
<div class="chat-container">
<div id="chat-box"></div>
<div class="chat-input-container">
<input type="text" id="chat-input" placeholder="Say something..." />
<button id="send-button">Send</button>
<input type="text" id="chat-input" placeholder="Say something..." />
<button id="send-button">Send</button>
</div>
</div>
<script>
@@ -16,7 +17,6 @@
const name = localStorage.getItem('username') || 'Anonymous';
socket.emit('join', { room, sender: name });
// Fetch message history
fetch(`/api/room/${room}/messages`)
.then(res => res.json())
@@ -47,8 +47,7 @@
chatBox.scrollTop = chatBox.scrollHeight;
});
// Send message
// Send message on button click
document.getElementById('send-button').onclick = () => {
const text = document.getElementById('chat-input').value;
const sender = localStorage.getItem('username') || 'Anonymous';
@@ -62,5 +61,13 @@
document.getElementById('chat-input').value = '';
}
};
// Send message on Enter key press
document.getElementById('chat-input').addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
document.getElementById('send-button').click();
}
});
</script>
{% endblock %}