Add room names to room view header, add a copy topic button and remove the display of the topics
This commit is contained in:
74
index.html
74
index.html
@ -46,10 +46,9 @@
|
||||
<div id="chat" class="hidden">
|
||||
<div id="header">
|
||||
<div id="details">
|
||||
<div>
|
||||
Topic: <span id="chat-room-topic"></span>
|
||||
</div>
|
||||
<div>
|
||||
<div style="display: inline;">
|
||||
<strong><span id="chat-room-name"></span></strong> | <a href="#" id="copy-topic-link" class="mini-button">Copy Topic</a>
|
||||
<span id="chat-room-topic" style="display: none;"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="user-list">
|
||||
@ -73,12 +72,71 @@
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const messageInput = document.getElementById('message');
|
||||
messageInput.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
const copyTopicLink = document.getElementById('copy-topic-link');
|
||||
const chatRoomTopic = document.getElementById('chat-room-topic');
|
||||
|
||||
if (messageInput) {
|
||||
messageInput.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
document.getElementById('message-form').dispatchEvent(new Event('submit'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (copyTopicLink) {
|
||||
copyTopicLink.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
document.getElementById('message-form').dispatchEvent(new Event('submit'));
|
||||
if (chatRoomTopic) {
|
||||
const topic = chatRoomTopic.innerText;
|
||||
navigator.clipboard.writeText(topic).then(() => {
|
||||
alert('Topic copied to clipboard!');
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy topic:', err);
|
||||
});
|
||||
} else {
|
||||
console.error('Element #chat-room-topic not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const switchRoom = (topic) => {
|
||||
console.log('Switching to room:', topic); // Debugging log
|
||||
const chatRoomTopic = document.querySelector('#chat-room-topic');
|
||||
const chatRoomName = document.querySelector('#chat-room-name');
|
||||
|
||||
if (chatRoomTopic) {
|
||||
chatRoomTopic.innerText = topic; // Set full topic here
|
||||
} else {
|
||||
console.error('Element #chat-room-topic not found');
|
||||
}
|
||||
});
|
||||
|
||||
if (chatRoomName) {
|
||||
// Update the room name in the header
|
||||
const room = config.rooms.find(r => r.topic === topic);
|
||||
const roomName = room ? room.alias : truncateHash(topic);
|
||||
chatRoomName.innerText = roomName;
|
||||
} else {
|
||||
console.error('Element #chat-room-name not found');
|
||||
}
|
||||
|
||||
clearMessages();
|
||||
renderMessagesForRoom(topic);
|
||||
|
||||
// Show chat UI elements
|
||||
document.querySelector('#chat').classList.remove('hidden');
|
||||
document.querySelector('#setup').classList.add('hidden');
|
||||
};
|
||||
|
||||
const roomList = document.querySelector('#room-list');
|
||||
if (roomList) {
|
||||
roomList.addEventListener('click', function(event) {
|
||||
const roomItem = event.target.closest('li');
|
||||
if (roomItem) {
|
||||
switchRoom(roomItem.dataset.topic);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user