From 060a91d2e1bf0d64216943d5ee91e2b9493cb8cd Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 11 Aug 2025 16:14:13 -0400 Subject: [PATCH] Fix voice persistence and dynamic room link updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voice Persistence: - Add voice/model saving to localStorage for persistent settings - Load voice from URL → localStorage → default priority order - Voice selection now persists across browser sessions and page refreshes Dynamic Room Links: - Add updateRoomLinksWithCurrentParams() function to update sidebar room links - Room links now dynamically update with current username, model, and voice settings - Both desktop and mobile room links stay synchronized with current parameters - Fixes issue where clicking room links would lose user's current settings Technical improvements: - Enhanced syncInputsAndQueryString() to save to localStorage and update room links - Initial sync call on page load ensures proper state from the start - Maintains backwards compatibility with existing functionality --- templates/base.html | 21 +++++++++++++++++++++ templates/chat.html | 18 +++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/templates/base.html b/templates/base.html index 7ed5d62..71c754a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -609,6 +609,27 @@ closeButton.style.display = "none"; } + // Function to update all room links with current URL parameters + function updateRoomLinksWithCurrentParams() { + const currentParams = new URLSearchParams(window.location.search).toString(); + + // Update desktop room links + const roomLinks = document.querySelectorAll('#rooms-list-ul a[href*="/chat/"]'); + roomLinks.forEach(link => { + const url = new URL(link.href, window.location.origin); + const roomPath = url.pathname; // e.g., "/chat/room-name" + link.href = roomPath + (currentParams ? '?' + currentParams : ''); + }); + + // Update mobile room links (if they exist) + const mobileRoomLinks = document.querySelectorAll('#rooms-list-modal-content a[href*="/chat/"]'); + mobileRoomLinks.forEach(link => { + const url = new URL(link.href, window.location.origin); + const roomPath = url.pathname; // e.g., "/chat/room-name" + link.href = roomPath + (currentParams ? '?' + currentParams : ''); + }); + } + // Function to create a new room function createNewRoom() { const roomName = document.getElementById("new-room-name").value.trim(); diff --git a/templates/chat.html b/templates/chat.html index 6b5419f..f95c73c 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -158,12 +158,21 @@ function syncInputsAndQueryString() { if (modelSelectMobile) modelSelectMobile.value = currentModel; if (voiceSelectMobile) voiceSelectMobile.value = currentVoice; + // Save to localStorage for persistence + localStorage.setItem('selectedModel', currentModel); + localStorage.setItem('selectedVoice', currentVoice); + // Update URL const newUrl = new URL(window.location.href); newUrl.searchParams.set("username", sanitizedUsername); newUrl.searchParams.set("model", currentModel); newUrl.searchParams.set("voice", currentVoice); window.history.replaceState({}, '', newUrl); + + // Update room links with new parameters + if (typeof updateRoomLinksWithCurrentParams === 'function') { + updateRoomLinksWithCurrentParams(); + } } // Backward compatibility @@ -231,9 +240,9 @@ document.addEventListener('DOMContentLoaded', (event) => { userHasScrolledUp = distanceFromBottom > 5; }); - // Set initial model, voice, and username from query string - const initialModel = urlParams.get("model") || "None"; - const initialVoice = urlParams.get("voice") || "onyx"; + // Set initial model, voice, and username from URL, localStorage, or defaults + const initialModel = urlParams.get("model") || localStorage.getItem('selectedModel') || "None"; + const initialVoice = urlParams.get("voice") || localStorage.getItem('selectedVoice') || "onyx"; const initialUsername = username; // Already set to URL param or "guest" modelSelectDesktop.value = initialModel; @@ -246,6 +255,9 @@ document.addEventListener('DOMContentLoaded', (event) => { const usernameInputMobile = document.getElementById("username-input-mobile"); if (usernameInputDesktop) usernameInputDesktop.value = initialUsername; if (usernameInputMobile) usernameInputMobile.value = initialUsername; + + // Initial sync to ensure localStorage and URL are updated with current values + syncInputsAndQueryString(); // Add event listeners for desktop dropdowns modelSelectDesktop.addEventListener("change", () => {