fix: try to improve topic indication and loading

This commit is contained in:
Andy Burke 2025-10-08 19:55:28 -07:00
parent 4c1fa98418
commit ac64473749
2 changed files with 13 additions and 17 deletions

View file

@ -10,23 +10,20 @@
} }
}); });
function update_topic_indicators() { function update_topic_indicators(event) {
const topic_indicators = document.querySelectorAll("[data-topic-selector-for]"); document
for (const topic_indicator of topic_indicators) { .querySelectorAll("[data-topic-selector-for]")
topic_indicator.classList.remove("active"); .forEach((element) => element.classList.remove("active"));
}
const topic_id = document.body.dataset.topic; const new_topic_id = event?.detail?.topic_id ?? document.body.dataset.topic;
if (!topic_id) {
if (!new_topic_id) {
return; return;
} }
const active_topic_indicators = document.querySelectorAll( document
`[data-topic-selector-for="${topic_id}"]`, .querySelectorAll(`[data-topic-selector-for="${new_topic_id}"]`)
); .forEach((element) => element.classList.add("active"));
for (const active_indicator of active_topic_indicators) {
active_indicator.classList.add("active");
}
} }
document.addEventListener("topics_updated", update_topic_indicators); document.addEventListener("topics_updated", update_topic_indicators);

View file

@ -129,11 +129,12 @@
const topic_id = event?.detail?.topic_id ?? document.body.dataset.topic; const topic_id = event?.detail?.topic_id ?? document.body.dataset.topic;
if (!topic_id) return; 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; const user = document.body.dataset.user ? JSON.parse(document.body.dataset.user) : null;
if (!user) return; if (!user) return;
const topic_chat_content = document.getElementById("topic-chat-content");
if (topic_polling_request_abort_controller) { if (topic_polling_request_abort_controller) {
topic_polling_request_abort_controller.abort(); topic_polling_request_abort_controller.abort();
topic_polling_request_abort_controller = null; topic_polling_request_abort_controller = null;
@ -149,8 +150,6 @@
const topic = await topic_response.json(); const topic = await topic_response.json();
topic_chat_content.innerHTML = "";
const events_response = await api.fetch( const events_response = await api.fetch(
`/api/topics/${topic_id}/events?type=chat&limit=100&sort=newest`, `/api/topics/${topic_id}/events?type=chat&limit=100&sort=newest`,
); );