Skip to content

Commit

Permalink
Split index action to index and scroll on threads
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Sep 27, 2023
1 parent b544716 commit ffa32a0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
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
28 changes: 16 additions & 12 deletions app/controllers/message_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit ffa32a0

Please sign in to comment.