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:
@@ -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 }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module Bucket::Broadcastable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
broadcasts_refreshes
|
||||
broadcasts_refreshes_to ->(bucket) { [ bucket.account, :buckets ] }
|
||||
end
|
||||
end
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %>
|
||||
Reference in New Issue
Block a user