Broadcast bucket changes to index page

This will cause each filtered view to stay updated as the items in the
buckets change.

For filters that are specific to buckets, we listen to broadcasts on
those buckets; for filters on "All projects" we listen instead for
broadcasts on an account-specific channel. This is so that "All
projects" views will be aware of any new buckets that are added, while
also avoid unnecessary refreshes from buckets that are filtered out.
This commit is contained in:
Kevin McConnell
2025-01-09 09:14:22 +00:00
parent 22be073a92
commit e7bc04856f
4 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class Bucket < ApplicationRecord
include Accessible, Filterable
include Accessible, Broadcastable, Filterable
belongs_to :account
belongs_to :creator, class_name: "User", default: -> { Current.user }
+8
View File
@@ -0,0 +1,8 @@
module Bucket::Broadcastable
extend ActiveSupport::Concern
included do
broadcasts_refreshes
broadcasts_refreshes_to ->(bucket) { [ bucket.account, :buckets ] }
end
end
+3
View File
@@ -1,5 +1,8 @@
<% @page_title = @filter.plain_summary %>
<% turbo_refreshes_with method: :morph, scroll: :preserve %>
<%= render "filters/broadcasts", filter: @filter %>
<% content_for :header do %>
<nav class="align-start">
<%= link_to root_path, class: "btn flex-item-justify-start" do %>
+7
View File
@@ -0,0 +1,7 @@
<% if filter.buckets.any? %>
<% filter.buckets.each do |bucket| %>
<%= turbo_stream_from bucket %>
<% end %>
<% else %>
<%= turbo_stream_from Current.account, :buckets %>
<% end %>