diff --git a/app/controllers/inbox_controller.rb b/app/controllers/inbox_controller.rb index cbb05b95..4b21210a 100644 --- a/app/controllers/inbox_controller.rb +++ b/app/controllers/inbox_controller.rb @@ -49,7 +49,7 @@ class InboxController < ApplicationController @disabled = true if @inbox.empty? respond_to do |format| format.html - format.js { render layout: false } + format.turbo_stream end end end diff --git a/app/views/inbox/show.haml b/app/views/inbox/show.haml index 7a817ad2..41966b5f 100644 --- a/app/views/inbox/show.haml +++ b/app/views/inbox/show.haml @@ -1,14 +1,12 @@ -#entries - - @inbox.each do |i| - = render "inbox/entry", i: i += turbo_frame_tag "inbox" do + #entries + - @inbox.each do |i| + = render "inbox/entry", i: i - - if @inbox.empty? - = t(".empty") + - if @inbox.empty? + = t(".empty") -= render "shared/cursored_pagination_dummy", more_data_available: @more_data_available, last_id: @inbox_last_id - -- if @more_data_available - - .d-flex.justify-content-center.justify-content-sm-start - %button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @inbox_last_id } } - = t("voc.load") + - if @more_data_available + .d-flex.justify-content-center.justify-content-sm-start#paginator + = button_to inbox_path(last_id: @inbox_last_id), class: "btn btn-light" do + = t("voc.load") diff --git a/app/views/inbox/show.js.erb b/app/views/inbox/show.js.erb deleted file mode 100644 index 1d7ece9a..00000000 --- a/app/views/inbox/show.js.erb +++ /dev/null @@ -1,9 +0,0 @@ -$('#entries').append('<% @inbox.each do |i| - %><%= j render 'inbox/entry', i: i -%><% end %>'); -<% if @more_data_available %> -$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @inbox_last_id %>'); -<% else %> -$('#pagination, #load-more-btn').remove(); -<% end %> -<% Inbox.where(id: @inbox.pluck(:id)).update_all(new: false) %> diff --git a/app/views/inbox/show.turbo_stream.haml b/app/views/inbox/show.turbo_stream.haml new file mode 100644 index 00000000..8dd7cd2e --- /dev/null +++ b/app/views/inbox/show.turbo_stream.haml @@ -0,0 +1,8 @@ += turbo_stream.append "entries" do + - @inbox.each do |i| + = render "inbox/entry", i: i + += turbo_stream.update "paginator" do + - if @more_data_available + = button_to t("voc.load"), inbox_path(last_id: @inbox_last_id), class: "btn btn-light" + diff --git a/config/routes.rb b/config/routes.rb index a1ab0fea..379d3030 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,8 +143,7 @@ Rails.application.routes.draw do get "/notifications(/:type)", to: "notifications#index", as: :notifications, defaults: { type: "new" } - get "/inbox", to: "inbox#show" - get "/inbox/:author", to: "inbox#show" + match "/inbox(/:author)", via: [:get, :post], to: "inbox#show", as: :inbox get "/user/:username(/p/:page)", to: "user#show", defaults: { page: 1 } get "/@:username(/p/:page)", to: "user#show", as: :user, defaults: { page: 1 }