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 %>
@@ -17,9 +17,9 @@ <% end %>
- <%= button_to notifications_mark_all_read_path, - class: "notification-tray__read_action btn btn--reversed fill-transparent borderless flex-item-justify-start shadow txt-xx-small", - data: { action: "click->dialog#close", turbo_frame: "notifications" } do %> + <%= button_to read_all_notifications_path, + class: "notification-tray__read_action btn btn--reversed fill-transparent borderless flex-item-justify-start shadow txt-xx-small", + data: { action: "click->dialog#close", turbo_frame: "notifications" } do %> <%= icon_tag "check" %> Mark all read <% end %> diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index bab485363..806615ce3 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -6,9 +6,8 @@

<%= @page_title %>

- <%= link_to notifications_settings_path, class: "btn flex-item-justify-end" do %> - <%= icon_tag "settings" %> - Notification settings + <%= link_to settings_notifications_path, class: "btn flex-item-justify-end" do %> + <%= icon_tag "settings" %> Notification settings <% end %> <% end %> @@ -18,9 +17,7 @@ <% if @unread.any? %>

New for you

- <%= button_to notifications_mark_all_read_path, class: "btn txt-small" do %> - Mark all as read - <% end %> + <%= button_to "Mark all as read", read_all_notifications_path, class: "btn txt-small" %>
<%= render @unread %> diff --git a/app/views/notifications/mark_read.turbo_stream.erb b/app/views/notifications/readings/create.turbo_stream.erb similarity index 100% rename from app/views/notifications/mark_read.turbo_stream.erb rename to app/views/notifications/readings/create.turbo_stream.erb diff --git a/config/routes.rb b/config/routes.rb index 6eb05dd50..beeae1a5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,20 +46,16 @@ Rails.application.routes.draw do end - resources :notifications, only: :index - namespace :notifications do - resource :tray, only: :show - resource :mark_all_read, only: :create - resources :mark_read, only: :create - resource :settings, only: :show - end - resources :notifications do - member do - post :mark_read + scope module: :notifications do + get "tray", to: "trays#show", on: :collection + get "settings", to: "settings#show", on: :collection + + post "readings", to: "readings#create_all", on: :collection, as: :read_all + post "reading", to: "readings#create", on: :member, as: :read end end - + resources :filters resources :events, only: :index diff --git a/test/controllers/notifications/mark_all_reads_controller_test.rb b/test/controllers/notifications/mark_all_reads_controller_test.rb index 2fa423b3a..31ca45a68 100644 --- a/test/controllers/notifications/mark_all_reads_controller_test.rb +++ b/test/controllers/notifications/mark_all_reads_controller_test.rb @@ -8,7 +8,7 @@ class Notifications::MarkAllReadsControllerTest < ActionDispatch::IntegrationTes test "show" do assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do assert_changes -> { notifications(:layout_commented_kevin).reload.read? }, from: false, to: true do - post notifications_mark_all_read_path + post read_all_notifications_path end end