From fd238ff7928278ae802bde68449ce77ee08951dc Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 6 Feb 2024 02:55:50 +0530 Subject: [PATCH] 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 --- src/interface/obsidian/src/chat_modal.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/interface/obsidian/src/chat_modal.ts b/src/interface/obsidian/src/chat_modal.ts index 2682fcd3..685fd91e 100644 --- a/src/interface/obsidian/src/chat_modal.ts +++ b/src/interface/obsidian/src/chat_modal.ts @@ -42,10 +42,6 @@ export class KhojChatModal extends Modal { // Create area for chat logs 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 let inputRow = contentEl.createDiv("khoj-input-row"); let clearChat = inputRow.createEl("button", { @@ -61,9 +57,7 @@ export class KhojChatModal extends Modal { attr: { id: "khoj-chat-input", autofocus: "autofocus", - placeholder: placeholderText, class: "khoj-chat-input option", - disabled: !getChatHistorySucessfully ? "disabled" : null }, }) chatInput.addEventListener('input', (_) => { this.onChatInput() }); @@ -93,6 +87,12 @@ export class KhojChatModal extends Modal { let sendImg = send.getElementsByClassName("lucide-arrow-up-circle")[0] 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 this.scrollChatToBottom(); chatInput.focus();