mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 05:39:11 +00:00
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
This commit is contained in:
@@ -541,6 +541,7 @@
|
|||||||
chatInput.value = chatInput.value.trimStart();
|
chatInput.value = chatInput.value.trimStart();
|
||||||
|
|
||||||
let questionStarterSuggestions = document.getElementById("question-starters");
|
let questionStarterSuggestions = document.getElementById("question-starters");
|
||||||
|
questionStarterSuggestions.innerHTML = "";
|
||||||
questionStarterSuggestions.style.display = "none";
|
questionStarterSuggestions.style.display = "none";
|
||||||
|
|
||||||
if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) {
|
if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) {
|
||||||
@@ -592,6 +593,7 @@
|
|||||||
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
||||||
|
|
||||||
let chatBody = document.getElementById("chat-body");
|
let chatBody = document.getElementById("chat-body");
|
||||||
|
chatBody.innerHTML = "";
|
||||||
let conversationId = chatBody.dataset.conversationId;
|
let conversationId = chatBody.dataset.conversationId;
|
||||||
let chatHistoryUrl = `/api/chat/history?client=desktop`;
|
let chatHistoryUrl = `/api/chat/history?client=desktop`;
|
||||||
if (conversationId) {
|
if (conversationId) {
|
||||||
@@ -672,11 +674,11 @@
|
|||||||
fetch(`${hostURL}/api/chat/starters?client=desktop`, { headers })
|
fetch(`${hostURL}/api/chat/starters?client=desktop`, { headers })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// Render chat options, if any
|
// Render conversation starters, if any
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
let questionStarterSuggestions = document.getElementById("question-starters");
|
let questionStarterSuggestions = document.getElementById("question-starters");
|
||||||
for (let index in data) {
|
questionStarterSuggestions.innerHTML = "";
|
||||||
let questionStarter = data[index];
|
data.forEach((questionStarter) => {
|
||||||
let questionStarterButton = document.createElement('button');
|
let questionStarterButton = document.createElement('button');
|
||||||
questionStarterButton.innerHTML = questionStarter;
|
questionStarterButton.innerHTML = questionStarter;
|
||||||
questionStarterButton.classList.add("question-starter");
|
questionStarterButton.classList.add("question-starter");
|
||||||
@@ -686,7 +688,7 @@
|
|||||||
chat();
|
chat();
|
||||||
});
|
});
|
||||||
questionStarterSuggestions.appendChild(questionStarterButton);
|
questionStarterSuggestions.appendChild(questionStarterButton);
|
||||||
}
|
});
|
||||||
questionStarterSuggestions.style.display = "grid";
|
questionStarterSuggestions.style.display = "grid";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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();
|
chatInput.value = chatInput.value.trimStart();
|
||||||
|
|
||||||
let questionStarterSuggestions = document.getElementById("question-starters");
|
let questionStarterSuggestions = document.getElementById("question-starters");
|
||||||
|
questionStarterSuggestions.innerHTML = "";
|
||||||
questionStarterSuggestions.style.display = "none";
|
questionStarterSuggestions.style.display = "none";
|
||||||
|
|
||||||
if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) {
|
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() {
|
function loadChat() {
|
||||||
let chatBody = document.getElementById("chat-body");
|
let chatBody = document.getElementById("chat-body");
|
||||||
|
chatBody.innerHTML = "";
|
||||||
let conversationId = chatBody.dataset.conversationId;
|
let conversationId = chatBody.dataset.conversationId;
|
||||||
let chatHistoryUrl = `/api/chat/history?client=web`;
|
let chatHistoryUrl = `/api/chat/history?client=web`;
|
||||||
if (conversationId) {
|
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
|
// Render chat options, if any
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
let questionStarterSuggestions = document.getElementById("question-starters");
|
let questionStarterSuggestions = document.getElementById("question-starters");
|
||||||
for (let index in data) {
|
questionStarterSuggestions.innerHTML = "";
|
||||||
let questionStarter = data[index];
|
data.forEach((questionStarter) => {
|
||||||
let questionStarterButton = document.createElement('button');
|
let questionStarterButton = document.createElement('button');
|
||||||
questionStarterButton.innerHTML = questionStarter;
|
questionStarterButton.innerHTML = questionStarter;
|
||||||
questionStarterButton.classList.add("question-starter");
|
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();
|
chat();
|
||||||
});
|
});
|
||||||
questionStarterSuggestions.appendChild(questionStarterButton);
|
questionStarterSuggestions.appendChild(questionStarterButton);
|
||||||
}
|
});
|
||||||
questionStarterSuggestions.style.display = "grid";
|
questionStarterSuggestions.style.display = "grid";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user