mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Load chat history after other elements in chat modal on Obsidian rendered
This reduces laggy feeling due to latency of loading chat history from server
This commit is contained in:
@@ -42,10 +42,6 @@ export class KhojChatModal extends Modal {
|
|||||||
// Create area for chat logs
|
// Create area for chat logs
|
||||||
let chatBodyEl = contentEl.createDiv({ attr: { id: "khoj-chat-body", class: "khoj-chat-body" } });
|
let chatBodyEl = contentEl.createDiv({ attr: { id: "khoj-chat-body", class: "khoj-chat-body" } });
|
||||||
|
|
||||||
// Get chat history from Khoj backend
|
|
||||||
let getChatHistorySucessfully = await this.getChatHistory(chatBodyEl);
|
|
||||||
let placeholderText = getChatHistorySucessfully ? "Message" : "Configure Khoj to enable chat";
|
|
||||||
|
|
||||||
// Add chat input field
|
// Add chat input field
|
||||||
let inputRow = contentEl.createDiv("khoj-input-row");
|
let inputRow = contentEl.createDiv("khoj-input-row");
|
||||||
let clearChat = inputRow.createEl("button", {
|
let clearChat = inputRow.createEl("button", {
|
||||||
@@ -61,9 +57,7 @@ export class KhojChatModal extends Modal {
|
|||||||
attr: {
|
attr: {
|
||||||
id: "khoj-chat-input",
|
id: "khoj-chat-input",
|
||||||
autofocus: "autofocus",
|
autofocus: "autofocus",
|
||||||
placeholder: placeholderText,
|
|
||||||
class: "khoj-chat-input option",
|
class: "khoj-chat-input option",
|
||||||
disabled: !getChatHistorySucessfully ? "disabled" : null
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
chatInput.addEventListener('input', (_) => { this.onChatInput() });
|
chatInput.addEventListener('input', (_) => { this.onChatInput() });
|
||||||
@@ -93,6 +87,12 @@ export class KhojChatModal extends Modal {
|
|||||||
let sendImg = <SVGElement>send.getElementsByClassName("lucide-arrow-up-circle")[0]
|
let sendImg = <SVGElement>send.getElementsByClassName("lucide-arrow-up-circle")[0]
|
||||||
sendImg.addEventListener('click', async (_) => { await this.chat() });
|
sendImg.addEventListener('click', async (_) => { await this.chat() });
|
||||||
|
|
||||||
|
// Get chat history from Khoj backend and set chat input state
|
||||||
|
let getChatHistorySucessfully = await this.getChatHistory(chatBodyEl);
|
||||||
|
let placeholderText = getChatHistorySucessfully ? "Message" : "Configure Khoj to enable chat";
|
||||||
|
chatInput.placeholder = placeholderText;
|
||||||
|
chatInput.disabled = !getChatHistorySucessfully;
|
||||||
|
|
||||||
// Scroll to bottom of modal, till the send message input box
|
// Scroll to bottom of modal, till the send message input box
|
||||||
this.scrollChatToBottom();
|
this.scrollChatToBottom();
|
||||||
chatInput.focus();
|
chatInput.focus();
|
||||||
|
|||||||
Reference in New Issue
Block a user