diff --git a/app/controllers/notifications/mark_all_reads_controller.rb b/app/controllers/notifications/mark_all_reads_controller.rb index 2aad42028..8b6450515 100644 --- a/app/controllers/notifications/mark_all_reads_controller.rb +++ b/app/controllers/notifications/mark_all_reads_controller.rb @@ -1,5 +1,18 @@ 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/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 1072680eb..493663428 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -13,19 +13,27 @@ <% end %>
- <% if @unread.any? %> -

New for you

- <%= render @unread %> - <% else %> -
- Nothing new for you. -
+ <%= 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 %> +
+ + <%= render @unread %> + <% else %> +
+ Nothing new for you. +
+ <% end %> <% end %>
<% if @page.records.any? %> -
-

Previously seen

+
+

Previously seen

<%= render @page.records %>
diff --git a/app/views/notifications/mark_all_reads/create.turbo_stream.erb b/app/views/notifications/mark_all_reads/create.turbo_stream.erb new file mode 100644 index 000000000..6d8b0f0a6 --- /dev/null +++ b/app/views/notifications/mark_all_reads/create.turbo_stream.erb @@ -0,0 +1,14 @@ +<%= 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