From 50617594fd3781080393ee8ca95cd82a44a1c66d Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 22 Feb 2024 20:11:03 +0530 Subject: [PATCH] Only show 3 starter questions even when consecutive chat sessions created Reset starter question suggestions before appending in web, desktop app Otherwise previously it'd keep adding to existing starter question suggestions on each new session creation if multiple consecutive new chat sessions created. This would result in more than the 3 expected starter questions being displayed at a time --- src/interface/desktop/chat.html | 10 ++++++---- src/khoj/interface/web/chat.html | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 455a8750..d7a10db6 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -541,6 +541,7 @@ chatInput.value = chatInput.value.trimStart(); let questionStarterSuggestions = document.getElementById("question-starters"); + questionStarterSuggestions.innerHTML = ""; questionStarterSuggestions.style.display = "none"; if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) { @@ -592,6 +593,7 @@ const headers = { 'Authorization': `Bearer ${khojToken}` }; let chatBody = document.getElementById("chat-body"); + chatBody.innerHTML = ""; let conversationId = chatBody.dataset.conversationId; let chatHistoryUrl = `/api/chat/history?client=desktop`; if (conversationId) { @@ -672,11 +674,11 @@ fetch(`${hostURL}/api/chat/starters?client=desktop`, { headers }) .then(response => response.json()) .then(data => { - // Render chat options, if any + // Render conversation starters, if any if (data.length > 0) { let questionStarterSuggestions = document.getElementById("question-starters"); - for (let index in data) { - let questionStarter = data[index]; + questionStarterSuggestions.innerHTML = ""; + data.forEach((questionStarter) => { let questionStarterButton = document.createElement('button'); questionStarterButton.innerHTML = questionStarter; questionStarterButton.classList.add("question-starter"); @@ -686,7 +688,7 @@ chat(); }); questionStarterSuggestions.appendChild(questionStarterButton); - } + }); questionStarterSuggestions.style.display = "grid"; } }) diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index 7ecb70d6..bed128d5 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -523,6 +523,7 @@ To get started, just start typing below. You can also type / to see a list of co chatInput.value = chatInput.value.trimStart(); let questionStarterSuggestions = document.getElementById("question-starters"); + questionStarterSuggestions.innerHTML = ""; questionStarterSuggestions.style.display = "none"; if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) { @@ -568,6 +569,7 @@ To get started, just start typing below. You can also type / to see a list of co function loadChat() { let chatBody = document.getElementById("chat-body"); + chatBody.innerHTML = ""; let conversationId = chatBody.dataset.conversationId; let chatHistoryUrl = `/api/chat/history?client=web`; if (conversationId) { @@ -650,8 +652,8 @@ To get started, just start typing below. You can also type / to see a list of co // Render chat options, if any if (data.length > 0) { let questionStarterSuggestions = document.getElementById("question-starters"); - for (let index in data) { - let questionStarter = data[index]; + questionStarterSuggestions.innerHTML = ""; + data.forEach((questionStarter) => { let questionStarterButton = document.createElement('button'); questionStarterButton.innerHTML = questionStarter; questionStarterButton.classList.add("question-starter"); @@ -661,7 +663,7 @@ To get started, just start typing below. You can also type / to see a list of co chat(); }); questionStarterSuggestions.appendChild(questionStarterButton); - } + }); questionStarterSuggestions.style.display = "grid"; } })