From ca91842c2d401afc4383c2823acf473e155cb0e2 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 27 Apr 2024 14:50:25 +0200 Subject: [PATCH] Fill channel selector using JavaScript Signed-off-by: Emmy D'Anello --- chat/static/chat.js | 18 +++++++++++++++++- chat/templates/chat/chat.html | 9 +-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/chat/static/chat.js b/chat/static/chat.js index 68d0c04..9172c97 100644 --- a/chat/static/chat.js +++ b/chat/static/chat.js @@ -60,11 +60,27 @@ function sendMessage() { function setChannels(new_channels) { channels = {} + let navTab = document.getElementById('nav-channels-tab') + navTab.innerHTML = '' + for (let channel of new_channels) { channels[channel['id']] = channel if (!messages[channel['id']]) messages[channel['id']] = new Map() + let navItem = document.createElement('li') + navItem.classList.add('list-group-item') + navItem.id = `tab-channel-${channel['id']}` + navItem.setAttribute('data-bs-dismiss', 'offcanvas') + navItem.onclick = () => selectChannel(channel['id']) + navTab.appendChild(navItem) + + let channelButton = document.createElement('button') + channelButton.classList.add('nav-link') + channelButton.type = 'button' + channelButton.innerText = channel['name'] + navItem.appendChild(channelButton) + fetchMessages(channel['id']) } @@ -73,7 +89,7 @@ function setChannels(new_channels) { } function receiveMessage(message) { - messages[message['channel_id']].push(message) + messages[message['channel_id']].set(message['id'], message) redrawMessages() } diff --git a/chat/templates/chat/chat.html b/chat/templates/chat/chat.html index 4318f36..81e5c21 100644 --- a/chat/templates/chat/chat.html +++ b/chat/templates/chat/chat.html @@ -13,14 +13,7 @@
- +