From e7bc04856f5818635cf21fffc46c22f9ce6479de Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Thu, 9 Jan 2025 09:14:22 +0000 Subject: [PATCH] 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. --- app/models/bucket.rb | 2 +- app/models/bucket/broadcastable.rb | 8 ++++++++ app/views/bubbles/index.html.erb | 3 +++ app/views/filters/_broadcasts.html.erb | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/models/bucket/broadcastable.rb create mode 100644 app/views/filters/_broadcasts.html.erb diff --git a/app/models/bucket.rb b/app/models/bucket.rb index ad8c0ce53..fcc3f34c7 100644 --- a/app/models/bucket.rb +++ b/app/models/bucket.rb @@ -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 } diff --git a/app/models/bucket/broadcastable.rb b/app/models/bucket/broadcastable.rb new file mode 100644 index 000000000..5406c23ef --- /dev/null +++ b/app/models/bucket/broadcastable.rb @@ -0,0 +1,8 @@ +module Bucket::Broadcastable + extend ActiveSupport::Concern + + included do + broadcasts_refreshes + broadcasts_refreshes_to ->(bucket) { [ bucket.account, :buckets ] } + end +end diff --git a/app/views/bubbles/index.html.erb b/app/views/bubbles/index.html.erb index 34096d4b7..bc43bf2ab 100644 --- a/app/views/bubbles/index.html.erb +++ b/app/views/bubbles/index.html.erb @@ -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 %>