From ac6447374928fae35fbcef9e86d61320a5509fc7 Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Wed, 8 Oct 2025 19:55:28 -0700 Subject: [PATCH] fix: try to improve topic indication and loading --- public/sidebar/sidebar.html | 23 ++++++++++------------- public/tabs/chat/chat.html | 7 +++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/public/sidebar/sidebar.html b/public/sidebar/sidebar.html index 39a4053..84bbded 100644 --- a/public/sidebar/sidebar.html +++ b/public/sidebar/sidebar.html @@ -10,23 +10,20 @@ } }); - function update_topic_indicators() { - const topic_indicators = document.querySelectorAll("[data-topic-selector-for]"); - for (const topic_indicator of topic_indicators) { - topic_indicator.classList.remove("active"); - } + function update_topic_indicators(event) { + document + .querySelectorAll("[data-topic-selector-for]") + .forEach((element) => element.classList.remove("active")); - const topic_id = document.body.dataset.topic; - if (!topic_id) { + const new_topic_id = event?.detail?.topic_id ?? document.body.dataset.topic; + + if (!new_topic_id) { return; } - const active_topic_indicators = document.querySelectorAll( - `[data-topic-selector-for="${topic_id}"]`, - ); - for (const active_indicator of active_topic_indicators) { - active_indicator.classList.add("active"); - } + document + .querySelectorAll(`[data-topic-selector-for="${new_topic_id}"]`) + .forEach((element) => element.classList.add("active")); } document.addEventListener("topics_updated", update_topic_indicators); diff --git a/public/tabs/chat/chat.html b/public/tabs/chat/chat.html index dacfde6..70670d9 100644 --- a/public/tabs/chat/chat.html +++ b/public/tabs/chat/chat.html @@ -129,11 +129,12 @@ const topic_id = event?.detail?.topic_id ?? document.body.dataset.topic; if (!topic_id) return; + const topic_chat_content = document.getElementById("topic-chat-content"); + topic_chat_content.innerHTML = ""; + const user = document.body.dataset.user ? JSON.parse(document.body.dataset.user) : null; if (!user) return; - const topic_chat_content = document.getElementById("topic-chat-content"); - if (topic_polling_request_abort_controller) { topic_polling_request_abort_controller.abort(); topic_polling_request_abort_controller = null; @@ -149,8 +150,6 @@ const topic = await topic_response.json(); - topic_chat_content.innerHTML = ""; - const events_response = await api.fetch( `/api/topics/${topic_id}/events?type=chat&limit=100&sort=newest`, );