From b8ecfa0125b90e9a7dbf20fea728c1f538d4316e Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Tue, 14 Jan 2025 14:23:46 +0000 Subject: [PATCH] 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. --- app/controllers/readings_controller.rb | 9 +++++++-- app/views/readings/create.turbo_stream.erb | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/readings_controller.rb b/app/controllers/readings_controller.rb index 5fc57ec9c..9c5798ed3 100644 --- a/app/controllers/readings_controller.rb +++ b/app/controllers/readings_controller.rb @@ -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 diff --git a/app/views/readings/create.turbo_stream.erb b/app/views/readings/create.turbo_stream.erb index 5d7fe7801..a66c881ce 100644 --- a/app/views/readings/create.turbo_stream.erb +++ b/app/views/readings/create.turbo_stream.erb @@ -1,3 +1,3 @@ -<% @notifications.each do |notification| %> - <%= turbo_stream.remove notification %> +<%= turbo_stream.update :notifications do %> + <%= render @notifications %> <% end %>