+ Moreā¦
@@ -17,22 +14,18 @@
<% 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 %>
- <%= icon_tag "check" %>
- Mark all read
+ <%= 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 %>
- <%= link_to notifications_path,
- class: "btn btn--reversed borderless fill-transparent translucent shadow center txt-uppercase txt-x-small",
- data: { action: "click->dialog#close"} do %>
- Notifications
- <% end %>
+ <%= link_to tag.span("Notifications"), notifications_path,
+ class: "btn btn--reversed borderless fill-transparent translucent shadow center txt-uppercase txt-x-small",
+ data: { action: "click->dialog#close" } %>
-
-<% end %>
+
+
diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb
index bab485363..bf83657ee 100644
--- a/app/views/notifications/index.html.erb
+++ b/app/views/notifications/index.html.erb
@@ -1,4 +1,5 @@
<% @page_title = "Notifications" %>
+<% @hide_footer_frames = true %>
<% content_for :header do %>
<% end %>
- <%= turbo_frame_tag "notifications_list" do %>
- <% if @unread.any? %>
-
-
New for you
- <%= button_to notifications_mark_all_read_path, class: "btn txt-small" do %>
- Mark all as read
- <% end %>
-
+ <% if @unread.any? %>
+
+
New for you
+ <%= button_to "Mark all as read", read_all_notifications_path, class: "btn txt-small" %>
+
- <%= render @unread %>
- <% else %>
-
- Nothing new for you.
-
- <% end %>
+ <%= render partial: "notifications/notification", collection: @unread, cached: true %>
+ <% else %>
+ <%# FIXME: Need to reveal this section if there are unread notification records in it %>
+
+ Nothing new for you.
+
<% end %>
-<% if @page.records.any? %>
-
- Previously seen
- <%= render @page.records %>
-
+<%# FIXME: Need to hide this section if there are no notification records in it, but then it needs to appear when any are added %>
+
+ Previously seen
- <%= notifications_next_page_link(@page) %>
-<% end %>
+
+ <%= render partial: "notifications/notification", collection: @page.records, cached: true %>
+
+
+
+<%= notifications_next_page_link(@page) if @page.records.any? %>
diff --git a/app/views/notifications/index.turbo_stream.erb b/app/views/notifications/index.turbo_stream.erb
index 00d744dcd..4d74e0941 100644
--- a/app/views/notifications/index.turbo_stream.erb
+++ b/app/views/notifications/index.turbo_stream.erb
@@ -1,7 +1,2 @@
-<%= turbo_stream.append :notifications_list_read do %>
- <%= render @page.records %>
-<% end %>
-
-<%= turbo_stream.replace :next_page do %>
- <%= notifications_next_page_link(@page) %>
-<% end %>
+<%= turbo_stream.append :notifications_list_read, partial: "notifications/notification", collection: @page.records %>
+<%= turbo_stream.replace :next_page, notifications_next_page_link(@page) %>
diff --git a/app/views/notifications/mark_all_reads/create.html.erb b/app/views/notifications/mark_all_reads/create.html.erb
deleted file mode 100644
index 52d6bcd10..000000000
--- a/app/views/notifications/mark_all_reads/create.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= turbo_frame_tag "notifications" %>
diff --git a/app/views/notifications/mark_all_reads/create.turbo_stream.erb b/app/views/notifications/mark_all_reads/create.turbo_stream.erb
deleted file mode 100644
index 6d8b0f0a6..000000000
--- a/app/views/notifications/mark_all_reads/create.turbo_stream.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<%= turbo_stream.update "notifications_list" do %>
-
- Nothing new for you.
-
-<% end %>
-
-<% if @page&.records&.any? %>
- <%= turbo_stream.update "notifications_list_read" do %>
-
Previously seen
- <%= render partial: "notifications/notification", collection: @page.records %>
- <% end %>
-<% end %>
-
-<%= turbo_stream.update "notifications" %>
\ No newline at end of file
diff --git a/app/views/notifications/mark_read.turbo_stream.erb b/app/views/notifications/mark_read.turbo_stream.erb
deleted file mode 100644
index 78996e2d3..000000000
--- a/app/views/notifications/mark_read.turbo_stream.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<%= turbo_stream.remove @notification %>
-
-<% if Current.user.notifications.unread.none? %>
- <%= turbo_stream.update "notifications_list" do %>
-
- Nothing new for you.
-
- <% end %>
-<% end %>
\ No newline at end of file
diff --git a/app/views/notifications/readings/create.turbo_stream.erb b/app/views/notifications/readings/create.turbo_stream.erb
new file mode 100644
index 000000000..44bf1e545
--- /dev/null
+++ b/app/views/notifications/readings/create.turbo_stream.erb
@@ -0,0 +1,2 @@
+<%= turbo_stream.remove @notification %>
+<%= turbo_stream.prepend :notifications_list_read, partial: "notifications/notification", locals: { notification: @notification } %>
diff --git a/app/views/notifications/trays/show.html.erb b/app/views/notifications/trays/show.html.erb
index 051055670..f61c52d51 100644
--- a/app/views/notifications/trays/show.html.erb
+++ b/app/views/notifications/trays/show.html.erb
@@ -1,3 +1,3 @@
<%= turbo_frame_tag "notifications" do %>
- <%= render collection: @notifications, partial: "notifications/notification" %>
+ <%= render partial: "notifications/notification", collection: @notifications, cached: true %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 6eb05dd50..61271338a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -46,17 +46,13 @@ 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
diff --git a/test/controllers/notifications/mark_all_reads_controller_test.rb b/test/controllers/notifications/mark_all_reads_controller_test.rb
deleted file mode 100644
index 2fa423b3a..000000000
--- a/test/controllers/notifications/mark_all_reads_controller_test.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "test_helper"
-
-class Notifications::MarkAllReadsControllerTest < ActionDispatch::IntegrationTest
- setup do
- sign_in_as :kevin
- end
-
- 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
- end
- end
-
- assert_response :success
- end
-end
diff --git a/test/controllers/notifications/readings_controller_test.rb b/test/controllers/notifications/readings_controller_test.rb
new file mode 100644
index 000000000..75a8a4875
--- /dev/null
+++ b/test/controllers/notifications/readings_controller_test.rb
@@ -0,0 +1,23 @@
+require "test_helper"
+
+class Notifications::ReadingsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in_as :kevin
+ end
+
+ test "create" do
+ assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do
+ post read_notification_path(notifications(:logo_published_kevin), format: :turbo_stream)
+ assert_response :success
+ end
+ end
+
+ test "create all" 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 read_all_notifications_path
+ assert_redirected_to notifications_path
+ end
+ end
+ end
+end
diff --git a/test/controllers/notifications/trays_controller_test.rb b/test/controllers/notifications/trays_controller_test.rb
index d49455ae1..07034fff0 100644
--- a/test/controllers/notifications/trays_controller_test.rb
+++ b/test/controllers/notifications/trays_controller_test.rb
@@ -6,7 +6,7 @@ class Notifications::TraysControllerTest < ActionDispatch::IntegrationTest
end
test "show" do
- get notifications_tray_path
+ get tray_notifications_path
assert_response :success
assert_select "div", text: /Layout is broken/