Skip to content

Commit

Permalink
Add conversation click event listener and menu item class
Browse files Browse the repository at this point in the history
  • Loading branch information
TotoB12 committed Jan 26, 2024
1 parent 89686f8 commit 59e093c
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sendButton = document.getElementById("send-button");
const newChatButton = document.getElementById("newChatButton");
const expanderButton = document.getElementById("expander-button");
const menuToggleCheckbox = document.querySelector("#menuToggle input");
const conversationElements = document.querySelectorAll('.conversation');
var transparentOverlay = document.getElementById('transparent-overlay');
var buffer;
let latestAIMessageElement = null;
Expand Down Expand Up @@ -132,7 +133,6 @@ function loadHistory() {
}
chatBox.scrollTop = chatBox.scrollHeight;
wrapCodeElements();
hljs.highlightAll();
}

function checkImageInHistory() {
Expand Down Expand Up @@ -289,6 +289,12 @@ function updateMenuWithConversations() {
: fourthMessage;

const menuItem = document.createElement("li");
menuItem.className = "conversation"; // Add this line
menuItem.dataset.uuid = key; // Store the UUID in a data attribute

menuItem.addEventListener('click', function() {
loadConversation(this.dataset.uuid); // Load the conversation when clicked
});

const titleContainer = document.createElement("div");
titleContainer.className = 'menu-title-container';
Expand Down Expand Up @@ -336,6 +342,12 @@ function loadConversation(uuid) {
updateChatBoxVisibility();
}

conversationElements.forEach(element => {
element.addEventListener('click', function() {
loadConversation(element.dataset.uuid);
});
});

function updateConnectionStatus(status) {
const connectionStatusElement = document.getElementById("connection-status");
if (status === "online") {
Expand All @@ -357,6 +369,7 @@ function simulateButtonHover() {

window.onload = function () {
startWebSocket();
hljs.configure({languages: []});
const path = window.location.pathname;
const pathParts = path.split("/");
inputField.focus();
Expand All @@ -379,6 +392,7 @@ window.onload = function () {
setupAnimCanvas();
update_anim(0);
updateMenuWithConversations();
wrapCodeElements();
};

function startWebSocket() {
Expand Down Expand Up @@ -422,7 +436,7 @@ function startWebSocket() {
}
} catch (e) {
processAIResponse(event.data);
hljs.highlightAll();
wrapCodeElements();
}
};

Expand Down Expand Up @@ -477,9 +491,9 @@ function processAIResponse(message, isError = false) {

const htmlContent = marked.parse(latestAIMessageElement.fullMessage);
latestAIMessageElement.innerHTML = htmlContent;
wrapCodeElements();
chatBox.scrollTop = chatBox.scrollHeight;
updateChatBoxVisibility();
wrapCodeElements();
}

function sendMessage() {
Expand Down Expand Up @@ -531,7 +545,6 @@ function sendMessage() {
uploadedImage = null;
ws.send(JSON.stringify(message));
disableUserInput();
hljs.highlightAll();
wrapCodeElements();
}

Expand Down Expand Up @@ -1045,6 +1058,7 @@ function setupAnimCanvas() {
}

function wrapCodeElements() {
hljs.highlightAll();
const codeElements = document.querySelectorAll("code");
codeElements.forEach((codeElement) => {
if (
Expand All @@ -1058,7 +1072,10 @@ function wrapCodeElements() {
wrapper.className = "code-wrapper";

const languageMatch = codeElement.className.match(/language-(\w+)/);
const language = languageMatch ? languageMatch[1] : "unknown";
let language = languageMatch ? languageMatch[1] : "language unknown";
if (language === "undefined") {
language = "unknown";
}

const languageBar = document.createElement("div");
languageBar.className = "language-bar";
Expand All @@ -1076,7 +1093,7 @@ function wrapCodeElements() {

setTimeout(() => {
copyIcon.textContent = "content_copy";
copyText.textContent = "Copy code";
copyText.textContent = "Copy";
}, 2000);
};

Expand All @@ -1095,5 +1112,4 @@ function wrapCodeElements() {
codeElement.parentNode.insertBefore(wrapper, codeElement);
wrapper.appendChild(codeElement);
});
}

}

0 comments on commit 59e093c

Please sign in to comment.