Broadcast new notifications

This commit is contained in:
Kevin McConnell
2025-01-10 13:40:38 +00:00
parent a7d9ec908c
commit 876083c697
5 changed files with 18 additions and 7 deletions
+13 -4
View File
@@ -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
+2
View File
@@ -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
+1 -1
View File
@@ -51,4 +51,4 @@
</ul>
</section>
<%= notification_tray_tag %>
<%= notification_tray %>
+1 -1
View File
@@ -77,4 +77,4 @@
<%= turbo_frame_tag dom_id(@bubble, :stage_picker), src: new_bucket_bubble_stage_picker_path(@bubble.bucket, @bubble) %>
</div>
<%= notification_tray_tag %>
<%= notification_tray %>
+1 -1
View File
@@ -21,4 +21,4 @@
<%= render @filters %>
</div>
<%= notification_tray_tag %>
<%= notification_tray %>