From ffa32a0f8c438157952eab1b2e2de64cf4f9028d Mon Sep 17 00:00:00 2001 From: stage-rl Date: Wed, 27 Sep 2023 08:41:16 +0200 Subject: [PATCH] Split index action to index and scroll on threads --- .../message_threads_table_component.html.erb | 2 +- app/controllers/message_threads_controller.rb | 28 +++++++++++-------- app/policies/message_thread_policy.rb | 4 +++ app/views/message_threads/index.html.erb | 2 +- ...rbo_stream.erb => scroll.turbo_stream.erb} | 2 +- config/routes.rb | 3 +- 6 files changed, 25 insertions(+), 16 deletions(-) rename app/views/message_threads/{index.turbo_stream.erb => scroll.turbo_stream.erb} (89%) diff --git a/app/components/message_threads_table_component.html.erb b/app/components/message_threads_table_component.html.erb index a4ceaa663..47943b7cb 100644 --- a/app/components/message_threads_table_component.html.erb +++ b/app/components/message_threads_table_component.html.erb @@ -1,6 +1,6 @@
- <%= form_with(url: merge_message_threads_path, local: true) do |form|%> + <%= form_with(url: merge_message_threads_path) do |form|%>
diff --git a/app/controllers/message_threads_controller.rb b/app/controllers/message_threads_controller.rb index b358dd723..a46012c11 100644 --- a/app/controllers/message_threads_controller.rb +++ b/app/controllers/message_threads_controller.rb @@ -18,24 +18,28 @@ def update def index authorize MessageThread + index_common + end + + def scroll + authorize MessageThread + index_common + end + def index_common cursor = MessageThreadCollection.init_cursor(search_params[:cursor]) - @message_threads, @next_cursor = MessageThreadCollection.all( - scope: message_thread_policy_scope.includes(:tags, :box), - search_permissions: search_permissions, - query: search_params[:q], - no_visible_tags: search_params[:no_visible_tags] == '1' && Current.user.admin?, - cursor: cursor - ) + @message_threads, @next_cursor = + MessageThreadCollection.all( + scope: message_thread_policy_scope.includes(:tags, :box), + search_permissions: search_permissions, + query: search_params[:q], + no_visible_tags: search_params[:no_visible_tags] == "1" && Current.user.admin?, + cursor: cursor + ) @next_cursor = MessageThreadCollection.serialize_cursor(@next_cursor) @next_page_params = search_params.to_h.merge(cursor: @next_cursor).merge(format: :turbo_stream) - - respond_to do |format| - format.html # GET - format.turbo_stream # POST - end end def merge diff --git a/app/policies/message_thread_policy.rb b/app/policies/message_thread_policy.rb index 6ba588a6a..f62e29c65 100644 --- a/app/policies/message_thread_policy.rb +++ b/app/policies/message_thread_policy.rb @@ -31,6 +31,10 @@ def index? true end + def scroll? + true + end + def update? true end diff --git a/app/views/message_threads/index.html.erb b/app/views/message_threads/index.html.erb index 7d3b4a33b..b63624c8e 100644 --- a/app/views/message_threads/index.html.erb +++ b/app/views/message_threads/index.html.erb @@ -8,7 +8,7 @@ <% component.with_next_page_area do %> <%= render Turbo::NextPageAreaComponent.new( id: @next_cursor, - url: message_threads_url(@next_page_params) + url: scroll_message_threads_url(@next_page_params) ) %> <% end %> diff --git a/app/views/message_threads/index.turbo_stream.erb b/app/views/message_threads/scroll.turbo_stream.erb similarity index 89% rename from app/views/message_threads/index.turbo_stream.erb rename to app/views/message_threads/scroll.turbo_stream.erb index 46fe76d81..b6aa7ab5b 100644 --- a/app/views/message_threads/index.turbo_stream.erb +++ b/app/views/message_threads/scroll.turbo_stream.erb @@ -7,7 +7,7 @@ <%= turbo_stream.append "next_page_area" do %> <%= render Turbo::NextPageComponent.new( id:@next_cursor, - url: message_threads_url(@next_page_params) + url: scroll_message_threads_url(@next_page_params) ) %> <% end %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index e0a106de0..a5d92f322 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,7 +50,8 @@ resources :message_threads do collection do - post 'merge' + post :merge + get :scroll end resources :messages end