mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 13:26:13 +00:00
Add and improve chat input pane, actions, icons on Obsidian client
- Move delete icon to left of chat input. This makes it harder to inadvertently click - Add send button to chat footer. Enter being the only way to send messages is not intuitive, outside standard modern UI patterns - Color chat message send button to make it primary CTA on web client - Make chat footer shorter. Use no or round border on action buttons
This commit is contained in:
@@ -17,17 +17,19 @@ export class KhojChatModal extends Modal {
|
|||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
|
|
||||||
// Register Modal Keybindings to send user message
|
// Register Modal Keybindings to send user message
|
||||||
this.scope.register([], 'Enter', async () => {
|
this.scope.register([], 'Enter', async () => { await this.chat() });
|
||||||
// Get text in chat input elmenet
|
}
|
||||||
let input_el = <HTMLInputElement>this.contentEl.getElementsByClassName("khoj-chat-input")[0];
|
|
||||||
|
|
||||||
// Clear text after extracting message to send
|
async chat() {
|
||||||
let user_message = input_el.value;
|
// Get text in chat input element
|
||||||
input_el.value = "";
|
let input_el = <HTMLInputElement>this.contentEl.getElementsByClassName("khoj-chat-input")[0];
|
||||||
|
|
||||||
// Get and render chat response to user message
|
// Clear text after extracting message to send
|
||||||
await this.getChatResponse(user_message);
|
let user_message = input_el.value.trim();
|
||||||
});
|
input_el.value = "";
|
||||||
|
|
||||||
|
// Get and render chat response to user message
|
||||||
|
await this.getChatResponse(user_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onOpen() {
|
async onOpen() {
|
||||||
@@ -42,10 +44,19 @@ export class KhojChatModal extends Modal {
|
|||||||
|
|
||||||
// Get chat history from Khoj backend
|
// Get chat history from Khoj backend
|
||||||
let getChatHistorySucessfully = await this.getChatHistory(chatBodyEl);
|
let getChatHistorySucessfully = await this.getChatHistory(chatBodyEl);
|
||||||
let placeholderText = getChatHistorySucessfully ? "Chat with Khoj [Hit Enter to send message]" : "Configure Khoj to enable chat";
|
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", {
|
||||||
|
text: "Clear History",
|
||||||
|
attr: {
|
||||||
|
class: "khoj-input-row-button clickable-icon",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
clearChat.addEventListener('click', async (_) => { await this.clearConversationHistory() });
|
||||||
|
setIcon(clearChat, "trash");
|
||||||
|
|
||||||
let chatInput = inputRow.createEl("input", {
|
let chatInput = inputRow.createEl("input", {
|
||||||
attr: {
|
attr: {
|
||||||
type: "text",
|
type: "text",
|
||||||
@@ -61,20 +72,21 @@ export class KhojChatModal extends Modal {
|
|||||||
text: "Transcribe",
|
text: "Transcribe",
|
||||||
attr: {
|
attr: {
|
||||||
id: "khoj-transcribe",
|
id: "khoj-transcribe",
|
||||||
class: "khoj-transcribe khoj-input-row-button",
|
class: "khoj-input-row-button clickable-icon ",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
transcribe.addEventListener('click', async (_) => { await this.speechToText() });
|
transcribe.addEventListener('click', async (_) => { await this.speechToText() });
|
||||||
setIcon(transcribe, "mic");
|
setIcon(transcribe, "mic");
|
||||||
|
|
||||||
let clearChat = inputRow.createEl("button", {
|
let send = inputRow.createEl("button", {
|
||||||
text: "Clear History",
|
text: "Send",
|
||||||
attr: {
|
attr: {
|
||||||
class: "khoj-input-row-button",
|
id: "khoj-chat-send",
|
||||||
|
class: "khoj-input-row-button clickable-icon",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
clearChat.addEventListener('click', async (_) => { await this.clearConversationHistory() });
|
send.addEventListener('click', async (_) => { await this.chat() });
|
||||||
setIcon(clearChat, "trash");
|
setIcon(send, "arrow-up-circle");
|
||||||
|
|
||||||
// Scroll to bottom of modal, till the send message input box
|
// Scroll to bottom of modal, till the send message input box
|
||||||
this.modalEl.scrollTop = this.modalEl.scrollHeight;
|
this.modalEl.scrollTop = this.modalEl.scrollHeight;
|
||||||
|
|||||||
@@ -230,36 +230,30 @@ img {
|
|||||||
}
|
}
|
||||||
.khoj-input-row {
|
.khoj-input-row {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto 32px 32px;
|
grid-template-columns: 32px auto 32px 32px;
|
||||||
grid-column-gap: 10px;
|
grid-column-gap: 10px;
|
||||||
grid-row-gap: 10px;
|
grid-row-gap: 10px;
|
||||||
background: var(--background-primary);
|
background: var(--background-primary);
|
||||||
|
margin: 0 0 0 -8px;
|
||||||
}
|
}
|
||||||
#khoj-chat-input.option:hover {
|
#khoj-chat-input.option:hover {
|
||||||
box-shadow: 0 0 11px var(--background-modifier-box-shadow);
|
box-shadow: 0 0 11px var(--background-modifier-box-shadow);
|
||||||
}
|
}
|
||||||
#khoj-chat-input {
|
#khoj-chat-input {
|
||||||
font-size: var(--font-ui-medium);
|
font-size: var(--font-ui-medium);
|
||||||
padding: 25px 20px;
|
padding: 0 0 0 12px;
|
||||||
|
border-radius: 16px;
|
||||||
|
height: 32px;
|
||||||
}
|
}
|
||||||
.khoj-input-row-button {
|
.khoj-input-row-button {
|
||||||
background: var(--background-primary);
|
border-radius: 50%;
|
||||||
border: none;
|
padding: 4px;
|
||||||
border-radius: 5px;
|
|
||||||
padding: 5px;
|
|
||||||
--icon-size: var(--icon-size);
|
--icon-size: var(--icon-size);
|
||||||
height: auto;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 300;
|
|
||||||
line-height: 1.5em;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background 0.3s ease-in-out;
|
|
||||||
}
|
}
|
||||||
.khoj-input-row-button:hover {
|
#khoj-chat-send .svg-icon {
|
||||||
background: var(--background-modifier-hover);
|
background: var(--khoj-sun);
|
||||||
}
|
border-radius: 50%;
|
||||||
.khoj-input-row-button:active {
|
color: #222;
|
||||||
background: var(--background-modifier-active);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (pointer: coarse), (hover: none) {
|
@media (pointer: coarse), (hover: none) {
|
||||||
|
|||||||
Reference in New Issue
Block a user