mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 06:55:21 +02:00
fix: maintain chat input focus after sending message
This commit is contained in:
parent
0d62e60da1
commit
602186f7a4
2 changed files with 25 additions and 1 deletions
|
@ -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
|
||||
|
|
21
app/views/messages/create.turbo_stream.erb
Normal file
21
app/views/messages/create.turbo_stream.erb
Normal 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 %>
|
Loading…
Add table
Add a link
Reference in a new issue