Skip to content

Commit

Permalink
Merge pull request #621 from PRX/sort-dropdown-fixes
Browse files Browse the repository at this point in the history
Sort Dropdown Fixes
  • Loading branch information
cavis committed Apr 26, 2023
2 parents 85494e1 + fead0c6 commit 5239c76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ class PodcastsController < ApplicationController
# Translate the user selected sort to a query order argument
DISPLAY_ORDER = {"A-Z" => {title: :asc},
"Z-A" => {title: :desc},
"" => {updated_at: :desc}}.freeze
"" => {updated_at: :desc},
"Recent Activity" => {updated_at: :desc}}.freeze

DEFAULT_PAGE_SIZE = 10

# GET /podcasts
def index
base_query = policy_scope(Podcast).page(params[:page]).per(DEFAULT_PAGE_SIZE).includes(default_feed: :feed_images)
@podcasts = add_sorting(base_query).filter_by_title(params[:q])
filtered_podcasts = base_query.filter_by_title(params[:q])
@podcasts = add_sorting(filtered_podcasts)

@published_episodes_counts = Episode.where(podcasts: @podcasts).published.group(:podcast_id).count
@scheduled_episodes_counts = Episode.where(podcasts: @podcasts).scheduled.group(:podcast_id).count
Expand Down
22 changes: 15 additions & 7 deletions app/views/podcasts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
<div class="d-grid d-lg-flex gap-2 align-items-center">
<h1 class="text-black fw-bold d-flex flex-fill my-4"><%= t(".my_podcasts") %></h1>

<a data-bs-toggle="dropdown">
<button class="btn btn-outline-light btn-sm dropdown-toggle">
Sort <span class="material-icons" style="color: green" aria-hidden="true" aria-hidden="true">sort</span>
<button class="btn btn-outline-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="material-icons" style="color: green" aria-hidden="true" aria-hidden="true">sort</span>
<% if params[:sort] == 'episode_count' %>
<span class="material-icons" aria-hidden="true">123</span>
<% elsif params[:sort] == 'A-Z' %>
<span>A-Z</span>
<% elsif params[:sort] == 'Z-A' %>
<span>Z-A</span>
<% else %>
<span class="material-icons" aria-hidden="true">timer</span>
<% end %>
</button>
<ul class="dropdown-menu">
<li><%= link_to "Recent Activity", podcasts_path(sort: "Recent"), class: "dropdown-item active" %></li>
<li><%= link_to "# of Episodes", podcasts_path(sort: "episode_count"), class: "dropdown-item" %></li>
<li><%= link_to "A-Z", podcasts_path(sort: "A-Z"), class: "dropdown-item" %></li>
<li><%= link_to "Z-A", podcasts_path(sort: "Z-A"), class: "dropdown-item" %></li>
<li><%= active_link_to "Recent Activity", podcasts_path(sort: "Recent Activity"), active: :exact, class: "dropdown-item text-decoration-none" %></li>
<li><%= active_link_to "# of Episodes", podcasts_path(sort: "episode_count"), active: :exact, class: "dropdown-item text-decoration-none" %></li>
<li><%= active_link_to "A-Z", podcasts_path(sort: "A-Z"), active: :exact, class: "dropdown-item text-decoration-none" %></li>
<li><%= active_link_to "Z-A", podcasts_path(sort: "Z-A"), active: :exact, class: "dropdown-item text-decoration-none" %></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 5239c76

Please sign in to comment.