diff --git a/core/static/index.js b/core/static/index.js index 4b78eb5..e2fe57a 100644 --- a/core/static/index.js +++ b/core/static/index.js @@ -5,105 +5,120 @@ Main js file for loading the dynamic UI elements. */ // Runs on inital startup, after window (html) has finished loading - init = () => { - document.getElementById('send_button').addEventListener('click', sendMessage) - document.getElementById('clear_log').addEventListener('click', clear_log) - - document.querySelector(".chatHistory").innerHTML += chatHistoryList() - - // To hide settings page when clicking somewhere else after it's opened. - document.addEventListener('click', function(event){ - const settings = document.getElementById("settingsPage"); - const settingsButton = document.getElementById("settingsButton"); - if(!settings.contains(event.target) && !settingsButton.contains(event.target) && settings.style.display=="block") { - settingsPage() - } - }); -} +init = () => { + document.getElementById("send_button").addEventListener("click", sendMessage); + document.getElementById("clear_log").addEventListener("click", clear_log); + + document.querySelector(".chatHistory").innerHTML += chatHistoryList(); + + // To hide settings page when clicking somewhere else after it's opened. + document.addEventListener("click", function (event) { + const settings = document.getElementById("settingsPage"); + const settingsButton = document.getElementById("settingsButton"); + if ( + !settings.contains(event.target) && + !settingsButton.contains(event.target) && + settings.style.display == "block" + ) { + settingsPage(); + } + }); +}; window.onload = init; // global state of the UI state = { - activeConversationId: 0, // The active conversation ID, so the UI knows what conversation to display and load. - userId: 0, // The user ID using the interface. probably not going to be used for a while. - totalTokensUsed: 0, // Track of total tokens and $$$ used - aiMessageId: 0 // The message id. Set when a response is received from the AI in chat.js -} + activeConversationId: 0, // The active conversation ID, so the UI knows what conversation to display and load. + userId: 0, // The user ID using the interface. probably not going to be used for a while. + totalTokensUsed: 0, // Track of total tokens and $$$ used + aiMessageId: 0, // The message id. Set when a response is received from the AI in chat.js +}; // Changes the loading icon -let loading = false +let loading = false; let setLoading = (newLoadingVal) => { - if(newLoadingVal){ - document.getElementById("chat_history").innerHTML += /* html */` + if (newLoadingVal) { + document.getElementById("chat_history").innerHTML += /* html */ `