From ce5cd81b10a741068a067a73a760f84b62ceaec6 Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Fri, 12 Sep 2025 15:26:13 -0700 Subject: [PATCH] fix: permission denied error and topic indicators --- public/index.html | 7 +++---- public/sidebar/sidebar.html | 25 ++++++++++++++++++++++++- public/tabs/chat/chat.js | 12 +++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/public/index.html b/public/index.html index 8a5dac6..6677d9a 100644 --- a/public/index.html +++ b/public/index.html @@ -48,7 +48,6 @@ if ( !document.body.dataset.topic || document.body.dataset.topic !== topic_id ) { const previous = document.body.dataset.topic; - document.body.dataset.topic = topic_id; console.dir( { topic_changed: { @@ -95,7 +94,10 @@ if ( first_topic_id ) { window.location.hash = `/topic/${ first_topic_id }/chat`; } + return; } + + document.body.dataset.topic = topic_id; }); let TOPICS = []; @@ -117,9 +119,6 @@ try { const topics_response = await api.fetch("/api/topics"); if (topics_response.ok) { - const topic_list = document.getElementById("topic-list"); - topic_list.innerHTML = ""; - const new_topics = await topics_response.json(); const has_differences = TOPICS.length !== new_topics.length || new_topics.some( (topic, index) => { return ( TOPICS[ index ]?.id !== topic.id || TOPICS[ index ]?.name !== topic.name ); diff --git a/public/sidebar/sidebar.html b/public/sidebar/sidebar.html index 113fefc..fef3c33 100644 --- a/public/sidebar/sidebar.html +++ b/public/sidebar/sidebar.html @@ -5,10 +5,33 @@ for (const topic of topics) { topic_list.insertAdjacentHTML( "beforeend", - `
  • ${topic.name}
  • `, + `
  • ${topic.name}
  • `, ); } }); + + 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"); + } + + const topic_id = document.body.dataset.topic; + if (!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.addEventListener("topics_updated", update_topic_indicators); + document.addEventListener("topic_changed", update_topic_indicators); + document.addEventListener("user_logged_in", update_topic_indicators);