From f77cf159ba757b27a37547af030a0307b73a3d2d Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:57:03 -0700 Subject: [PATCH] UI: fix a glitch when switching tabs with "show controls" unchecked --- js/main.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/js/main.js b/js/main.js index 22fe4149..6b456517 100644 --- a/js/main.js +++ b/js/main.js @@ -7,30 +7,30 @@ main_parent.parentNode.style = "gap: 0"; main_parent.parentNode.parentNode.style = "padding: 0"; document.querySelector(".header_bar").addEventListener("click", function(event) { - if (event.target.tagName === "BUTTON") { - const buttonText = event.target.textContent.trim(); + if (event.target.tagName !== "BUTTON") return; - let chat_visible = (buttonText == "Chat"); - let default_visible = (buttonText == "Default"); - let notebook_visible = (buttonText == "Notebook"); + const buttonText = event.target.textContent.trim(); + const extensionsVisible = ["Chat", "Default", "Notebook"].includes(buttonText); + const chatVisible = buttonText === "Chat"; + const showControlsChecked = document.querySelector("#show-controls input").checked; + const extensions = document.querySelector("#extensions"); - // Check if one of the generation tabs is visible - if (chat_visible || notebook_visible || default_visible) { - extensions && (extensions.style.display = "flex"); - - if (chat_visible) { - this.style.marginBottom = "0px"; - extensions && (extensions.style.maxWidth = "880px"); - extensions && (extensions.style.padding = "0px"); - } else { - this.style.marginBottom = "19px"; - extensions && (extensions.style.maxWidth = "none"); - extensions && (extensions.style.padding = "15px"); - } - } else { - this.style.marginBottom = "19px"; - extensions && (extensions.style.display = "none"); + if (extensionsVisible) { + if (extensions) { + extensions.style.display = "flex"; + extensions.style.maxWidth = chatVisible ? "880px" : "none"; + extensions.style.padding = chatVisible ? "0px" : "15px"; } + this.style.marginBottom = chatVisible ? "0px" : "19px"; + + if (chatVisible && !showControlsChecked) { + document.querySelectorAll("#chat-tab > div > :nth-child(n+2), #extensions").forEach(element => { + element.style.display = "none"; + }); + } + } else { + this.style.marginBottom = "19px"; + if (extensions) extensions.style.display = "none"; } });