From 6c8fe164b3369c992bc3f0c973728ed3fe18e146 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Thu, 17 Apr 2025 09:37:34 +0100 Subject: [PATCH] Read a card should dismiss all notifications Previous code assumed that there was a single notification to dismiss for that card, but in practice there can be zero or many. If it's zero, we need to avoid the crash. If it's many, we should dismiss them all. Also re-rendering the notification stack after dismissing enables us to remove all the removed cards, as well as reveal any older ones that were previously outside the visible page size. This reverts commit 6135909b7e7b34ffdc7430a8b609c1b561085ba4. --- app/controllers/cards/readings_controller.rb | 4 ++-- app/views/cards/readings/create.turbo_stream.erb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/cards/readings_controller.rb b/app/controllers/cards/readings_controller.rb index bbc4d53c0..dbb379b15 100644 --- a/app/controllers/cards/readings_controller.rb +++ b/app/controllers/cards/readings_controller.rb @@ -2,7 +2,7 @@ class Cards::ReadingsController < ApplicationController include CardScoped def create - @notification = Current.user.notifications.find_by(card: @card) - @notification.read + Current.user.notifications.unread.where(card: @card).read_all + @notifications = Current.user.notifications.unread.ordered.limit(20) end end diff --git a/app/views/cards/readings/create.turbo_stream.erb b/app/views/cards/readings/create.turbo_stream.erb index 1f3b07b47..8f758752e 100644 --- a/app/views/cards/readings/create.turbo_stream.erb +++ b/app/views/cards/readings/create.turbo_stream.erb @@ -1 +1,3 @@ -<%= turbo_stream.remove @notification %> +<%= turbo_stream.update "notifications" do %> + <%= render collection: @notifications, partial: "notifications/notification" %> +<% end %>