mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 13:26:13 +00:00
Reduce promise based nesting in chat JS func used in desktop, web client
Use async/await to reduce .then() based nesting to improve code readability
This commit is contained in:
@@ -346,8 +346,7 @@
|
||||
chatInput.classList.remove("option-enabled");
|
||||
|
||||
// Call specified Khoj API which returns a streamed response of type text/plain
|
||||
fetch(url, { headers })
|
||||
.then(response => {
|
||||
let response = await fetch(url, { headers });
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let rawResponse = "";
|
||||
@@ -454,7 +453,6 @@
|
||||
});
|
||||
}
|
||||
readStream();
|
||||
});
|
||||
}
|
||||
|
||||
function incrementalChat(event) {
|
||||
|
||||
@@ -309,7 +309,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
return element
|
||||
}
|
||||
|
||||
function chat() {
|
||||
async function chat() {
|
||||
// Extract required fields for search from form
|
||||
let query = document.getElementById("chat-input").value.trim();
|
||||
let resultsCount = localStorage.getItem("khojResultsCount") || 5;
|
||||
@@ -351,8 +351,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
chatInput.classList.remove("option-enabled");
|
||||
|
||||
// Call specified Khoj API which returns a streamed response of type text/plain
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
let response = await fetch(url);
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let rawResponse = "";
|
||||
@@ -458,8 +457,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
});
|
||||
}
|
||||
readStream();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function incrementalChat(event) {
|
||||
if (!event.shiftKey && event.key === 'Enter') {
|
||||
|
||||
Reference in New Issue
Block a user