Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): Disable chat input when sending input #1781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion js/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ class ChatInput extends LightElement {
this.#onInput();
}

// Recheck button state when `this.disabled` updates
updated(changedProperties: Map<string, unknown>) {
if (changedProperties.has("disabled")) {
this.#onInput();
}
}

#sendInput(): void {
if (this.valueIsEmpty) return;
if (this.disabled) return;
Expand All @@ -282,11 +289,11 @@ class ChatInput extends LightElement {
this.setInputValue("");

this.textarea.focus();
this.disabled = true; // Will be re-enabled by #finalizeMessage() when we get a response
}

setInputValue(value: string): void {
this.textarea.value = value;
this.disabled = value.trim().length === 0;

// Simulate an input event (to trigger the textarea autoresize)
const inputEvent = new Event("input", { bubbles: true, cancelable: true });
Expand Down Expand Up @@ -451,6 +458,7 @@ class ChatContainer extends LightElement {
}

#finalizeMessage(): void {
console.log("message finalized!");
this.input.disabled = false;
}

Expand Down
2 changes: 1 addition & 1 deletion shiny/www/py-shiny/chat/chat.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions shiny/www/py-shiny/chat/chat.js.map

Large diffs are not rendered by default.

Loading