1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-08 15:05:22 +02:00

fix: maintain chat input focus after sending message

This commit is contained in:
Huy Nguyen Quang 2025-06-11 22:48:27 +07:00
parent 0d62e60da1
commit 602186f7a4
2 changed files with 25 additions and 1 deletions

View file

@ -10,7 +10,10 @@ class MessagesController < ApplicationController
ai_model: message_params[:ai_model]
)
redirect_to chat_path(@chat, thinking: true)
respond_to do |format|
format.html { redirect_to chat_path(@chat, thinking: true) }
format.turbo_stream
end
end
private

View file

@ -0,0 +1,21 @@
<%# Add thinking indicator to messages area %>
<%= turbo_stream.append "messages" do %>
<%= render "chats/thinking_indicator", chat: @chat %>
<% end %>
<%# Reset the form by replacing it with a fresh version %>
<%= turbo_stream.replace "chat-form" do %>
<%= render "messages/chat_form", chat: @chat %>
<% end %>
<%# Focus the input after form replacement %>
<%= turbo_stream.after "chat-form" do %>
<script>
requestAnimationFrame(() => {
const textarea = document.querySelector('[data-chat-target="input"]');
if (textarea) {
textarea.focus();
}
});
</script>
<% end %>