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

How can I broadcast turbo_stream.scroll_into_view? #45

Open
remy727 opened this issue Jan 14, 2025 · 0 comments
Open

How can I broadcast turbo_stream.scroll_into_view? #45

remy727 opened this issue Jan 14, 2025 · 0 comments

Comments

@remy727
Copy link

remy727 commented Jan 14, 2025

Hello
Thank you for working on turbo_power 💪

I want to accomplish this:

image

app/models/message.rb

class Message < ApplicationRecord
  include Turbo::Streams::ActionHelper
  include Turbo::Streams::StreamName

  belongs_to :conversation

  after_create_commit :broadcast_message_in_conversation

  def broadcast_message_in_conversation
    broadcast_append_to(
      [conversation, :messages],
      partial: "/conversations/message",
      locals: { message: self },
      target: dom_id(conversation, :messages),
    )
    
    # I want to scroll to the bottom of the conversation after the new message is rendered.
    content = turbo_stream_action_tag :scroll_into_view, target: dom_id(self, :container)
    ActionCable.server.broadcast(stream_name_from(self), content)
  end
end

app/views/conversations/_message.rb

<%= tag.div id: dom_id(message, :container) %>
  <p class="message"><%= sanitize(message.message) %></p>
<% end %>

The above has no errors but doesn't scroll to the bottom.

Any thoughts?

Thank you in advance

Note - this issue was created on turbo_power before but I think this issue is more fit here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant