diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index f159c1200..8ac611eb4 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -1,7 +1,16 @@ module NotificationsHelper - def notification_tray_tag - tag.div id: "notification-tray", class: "notification-tray", data: { turbo_permanent: true } do - turbo_frame_tag "notifications", src: notifications_path - end + def notification_tray + notification_stream_tag + notification_tray_tag end + + private + def notification_stream_tag + turbo_stream_from Current.user, :notifications + end + + def notification_tray_tag + tag.div id: "notification-tray", class: "notification-tray", data: { turbo_permanent: true } do + turbo_frame_tag("notifications", src: notifications_path) + end + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 20dea8f11..deaa9934a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -5,4 +5,6 @@ class Notification < ApplicationRecord scope :unread, -> { where(read: false) } scope :ordered, -> { order(read: :desc, created_at: :desc) } + + broadcasts_to ->(notification) { [ notification.user, :notifications ] }, inserts_by: :prepend end diff --git a/app/views/bubbles/index.html.erb b/app/views/bubbles/index.html.erb index 7928afacf..a35ba09c9 100644 --- a/app/views/bubbles/index.html.erb +++ b/app/views/bubbles/index.html.erb @@ -51,4 +51,4 @@ -<%= notification_tray_tag %> +<%= notification_tray %> diff --git a/app/views/bubbles/show.html.erb b/app/views/bubbles/show.html.erb index 681f91845..938fcd864 100644 --- a/app/views/bubbles/show.html.erb +++ b/app/views/bubbles/show.html.erb @@ -77,4 +77,4 @@ <%= turbo_frame_tag dom_id(@bubble, :stage_picker), src: new_bucket_bubble_stage_picker_path(@bubble.bucket, @bubble) %> -<%= notification_tray_tag %> +<%= notification_tray %> diff --git a/app/views/buckets/index.html.erb b/app/views/buckets/index.html.erb index 22a1e00ce..b53e188fd 100644 --- a/app/views/buckets/index.html.erb +++ b/app/views/buckets/index.html.erb @@ -21,4 +21,4 @@ <%= render @filters %> -<%= notification_tray_tag %> +<%= notification_tray %>