Skip to content

Commit 34ba170

Browse files
committed
feature/Use rails views for folder show
1 parent dafb773 commit 34ba170

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

app/controllers/folders_controller.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def index
3030

3131
@folders = current_user.folders
3232

33-
@folders = @folders.where('name ILIKE ?', "%#{params[:search]}%") if params[:search]
33+
@folders = @folders.where('name ILIKE ?', "%#{params[:search]}%") if params[:search].present?
3434

3535
@folders = @folders
3636
.order(name: :asc)
@@ -49,7 +49,24 @@ def index
4949

5050
def show
5151
@page_title = @folder.name
52-
@snippets = @folder.snippets.order(created_at: :desc).map { |s| s.serialize(current_user) }
52+
@display_popover = true
53+
@snippets = @folder.snippets
54+
55+
@snippets = @snippets.where('description ILIKE ?', "%#{params[:search]}%") if params[:search].present?
56+
57+
@snippets = @snippets
58+
.order(created_at: :desc)
59+
.paginate(page: params[:page] || 1, per_page: 6)
60+
61+
respond_to do |format|
62+
format.html
63+
format.json do
64+
render json: {
65+
entries: render_to_string(partial: 'snippets/snippets', formats: [:html]),
66+
pagination: view_context.will_paginate(@snippets)
67+
}
68+
end
69+
end
5370
end
5471

5572
def new

app/views/folders/show.html.erb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
<folders-show
2-
:folder="<%= @folder.to_json %>"
3-
:snippets="<%= @snippets.to_json %>">
4-
</folders-show>
1+
<div data-controller="infinite-scroll" data-infinite-scroll-base-url="<%= folder_path(@folder) %>">
2+
<div style="display: flex; align-items: center; justify-content: space-between;" class="margin-top">
3+
4+
<div class="searchbar">
5+
<input autofocus
6+
type="text"
7+
placeholder="Search"
8+
data-action="input->infinite-scroll#search"
9+
data-target="infinite-scroll.input"
10+
/>
11+
<img src="/icons/search.svg">
12+
</div>
13+
14+
<%= link_to 'NEW SNIPPET', new_snippet_path, class: 'button--cta-new' %>
15+
</div>
16+
17+
<div class="margin-top"
18+
data-target="infinite-scroll.entries"
19+
data-action="scroll@window->infinite-scroll#scroll"
20+
>
21+
<%= render 'snippets/snippets' %>
22+
</div>
23+
24+
<div data-target="infinite-scroll.pagination" class="hidden">
25+
<%= will_paginate @snippets, container: false %>
26+
</div>
27+
</div>

0 commit comments

Comments
 (0)