Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split index action to index and scroll on threads #65

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/message_threads_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex flex-col justify-stretch items-stretch gap-4 p-4">
<div class="flex flex-col justify-stretch items-stretch rounded-md bg-white border border-gray-200">
<%= form_with(url: merge_message_threads_path, local: true) do |form|%>
<%= form_with(url: merge_message_threads_path) do |form|%>
<div class="flex justify-stretch items-center gap-4 p-4 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="todo flex justify-start items-start pr-[100px]">
<div class=" w-4 h-4 relative">
Expand Down
27 changes: 15 additions & 12 deletions app/controllers/message_threads_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MessageThreadsController < ApplicationController
before_action :set_message_thread, only: %i[show update]
before_action :load_threads, only: %i[index scroll]

def show
authorize @message_thread
Expand All @@ -18,24 +19,26 @@ def update

def index
authorize MessageThread
end

def scroll
authorize MessageThread
end

def load_threads
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
Expand Down
4 changes: 4 additions & 0 deletions app/policies/message_thread_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def index?
true
end

def scroll?
true
end

def update?
true
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/message_threads/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@

resources :message_threads do
collection do
post 'merge'
post :merge
get :scroll
end
resources :messages
end
Expand Down
Loading