diff --git a/app/controllers/notifications/mark_all_reads_controller.rb b/app/controllers/notifications/mark_all_reads_controller.rb deleted file mode 100644 index 8b6450515..000000000 --- a/app/controllers/notifications/mark_all_reads_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Notifications::MarkAllReadsController < ApplicationController - def create - Current.user.notifications.unread.read_all - - set_page_and_extract_portion_from Current.user.notifications.read.ordered if request.format.turbo_stream? - - Turbo::StreamsChannel.broadcast_update_to( - [ Current.user, :notifications ], - target: "notifications", - html: "" - ) - - respond_to do |format| - format.turbo_stream - format.html - end - end -end diff --git a/app/controllers/notifications/readings_controller.rb b/app/controllers/notifications/readings_controller.rb new file mode 100644 index 000000000..9da4fb827 --- /dev/null +++ b/app/controllers/notifications/readings_controller.rb @@ -0,0 +1,14 @@ +class Notifications::ReadingsController < ApplicationController + def create + @notification = Current.user.notifications.find(params[:id]) + @notification.update!(read_at: Time.current) + end + + def create_all + Current.user.notifications.unread.read_all + + set_page_and_extract_portion_from Current.user.notifications.read.ordered if request.format.turbo_stream? + + Turbo::StreamsChannel.broadcast_update_to [ Current.user, :notifications ], target: "notifications", html: "" + end +end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 403828c2b..83e5db488 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -6,14 +6,4 @@ class NotificationsController < ApplicationController @unread = Current.user.notifications.unread.ordered end end - - def mark_read - @notification = Current.user.notifications.find(params[:id]) - @notification.update!(read_at: Time.current) - - respond_to do |format| - format.html { redirect_back fallback_location: notifications_path } - format.turbo_stream - end - end end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index ca62626cf..656edad54 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -32,7 +32,7 @@ module NotificationsHelper end def notification_mark_read_button(notification) - button_to mark_read_notification_path(notification), + button_to read_notification_path(notification), class: "notification__unread_indicator btn borderless", title: "Mark as read", data: { turbo_frame: "_top" } do diff --git a/app/views/notifications/_tray.html.erb b/app/views/notifications/_tray.html.erb index 8e12e58f4..390e47054 100644 --- a/app/views/notifications/_tray.html.erb +++ b/app/views/notifications/_tray.html.erb @@ -6,7 +6,7 @@ dialog_modal_value: false, dialog_target: "dialog", action: "keydown.esc->dialog#close:stop click@document->dialog#closeOnClickOutside" } do %> - <%= turbo_frame_tag("notifications", src: notifications_tray_path) -%> + <%= turbo_frame_tag("notifications", src: tray_notifications_path) -%> <%= link_to notifications_path, class: "tray__overflow border-radius txt-normal", data: { action: "click->dialog#close"} do %>