Replace notifications on read, instead of removing

Previously when a notification was read, we'd remove it from the list.
This will often be fine, but if there were more unread notifications
that hadn't been loaded yet (because there were too many for the initial
page) then the list could become empty when really there are still more
items to show.

So instead of removing the items when they're read, we can reload the
list with the new page of items. This should allow the older
notifications to come into view when necessary.
This commit is contained in:
Kevin McConnell
2025-01-14 14:23:46 +00:00
parent 9fc5311ddc
commit b8ecfa0125
2 changed files with 9 additions and 4 deletions
+7 -2
View File
@@ -2,7 +2,12 @@ class ReadingsController < ApplicationController
include BubbleScoped, BucketScoped
def create
@notifications = Current.user.notifications.where(bubble: @bubble)
@notifications.update(read: true)
mark_bubble_notifications_read
@notifications = Current.user.notifications.unread.ordered.limit(20)
end
private
def mark_bubble_notifications_read
Current.user.notifications.where(bubble: @bubble).update(read: true)
end
end
+2 -2
View File
@@ -1,3 +1,3 @@
<% @notifications.each do |notification| %>
<%= turbo_stream.remove notification %>
<%= turbo_stream.update :notifications do %>
<%= render @notifications %>
<% end %>