|
30 | 30 | <div class="space-y-8"> |
31 | 31 | <!-- Header --> |
32 | 32 | <h1 class="text-4xl font-black text-gray-900 mb-4"><%= t('users.index.title') %></h1> |
33 | | - <p class="text-lg text-gray-600"> |
34 | | - <%= t('users.index.description') %> |
35 | | - </p> |
| 33 | + <div class="md:flex md:items-center md:justify-between w-full"> |
| 34 | + <p class="text-left text-lg text-gray-600 md:flex-1 min-w-0"> |
| 35 | + <% if user_signed_in? %> |
| 36 | + <%= t('users.index.description', count: (@users.respond_to?(:total_count) ? @users.total_count : @users.count)) %> |
| 37 | + <% else %> |
| 38 | + <%= link_to t('users.index.join'), github_auth_with_return_path, class: "underline hover:text-red-600 transition-colors" %> |
| 39 | + <%= t('users.index.join_suffix', count: (@users.respond_to?(:total_count) ? @users.total_count : @users.count)) %> |
| 40 | + <% end %> |
| 41 | + </p> |
| 42 | + |
| 43 | + <div class="relative md:ml-auto mt-2 md:mt-0 flex-shrink-0" data-controller="dropdown"> |
| 44 | + <button type="button" class="flex items-center gap-x-1 text-sm rounded-full cursor-pointer bg-gray-100 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 px-3 py-2" data-action="click->dropdown#toggle click@window->dropdown#hide"> |
| 45 | + <span class="text-gray-400"><%= t('users.index.sort_label') %>:</span> |
| 46 | + <span class="text-gray-700 font-medium"> |
| 47 | + <% effective_sort = (@sort == 'old' ? 'new' : @sort) %> |
| 48 | + <% effective_dir = (@sort == 'old' ? 'asc' : @dir) %> |
| 49 | + <% closed_label = case effective_sort |
| 50 | + when 'new' then (effective_dir == 'asc' ? t('users.index.sort.new_reverse') : t('users.index.sort.new')) |
| 51 | + when 'projects' then (effective_dir == 'asc' ? t('users.index.sort.projects_reverse') : t('users.index.sort.projects')) |
| 52 | + when 'posts' then (effective_dir == 'asc' ? t('users.index.sort.posts_reverse') : t('users.index.sort.posts')) |
| 53 | + when 'comments' then (effective_dir == 'asc' ? t('users.index.sort.comments_reverse') : t('users.index.sort.comments')) |
| 54 | + when 'stars' then (effective_dir == 'asc' ? t('users.index.sort.stars_reverse') : t('users.index.sort.stars')) |
| 55 | + when 'az' then (effective_dir == 'asc' ? t('users.index.sort.az') : t('users.index.sort.az_reverse')) |
| 56 | + else (effective_dir == 'asc' ? t('users.index.sort.top_reverse') : t('users.index.sort.top')) |
| 57 | + end %> |
| 58 | + <%= closed_label %> |
| 59 | + </span> |
| 60 | + <%= inline_svg_tag "chevron-down.svg", class: "ml-1 h-5 w-5 text-gray-400" %> |
| 61 | + </button> |
| 62 | + |
| 63 | + <div class="hidden absolute mt-2 w-64 divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-none left-0 md:left-auto md:right-0 origin-top-left md:origin-top-right" data-dropdown-target="menu"> |
| 64 | + <div class="py-1"> |
| 65 | + <% # Helper to compute label and dir per option, showing the opposite for current based on direction %> |
| 66 | + <% def sort_link(label_key, reverse_label_key, key, current_sort, current_dir, filters) |
| 67 | + is_current = (current_sort == key) |
| 68 | + label = if is_current |
| 69 | + # If currently ascending, opposite is descending -> use main label; if descending, opposite is ascending -> use reverse label |
| 70 | + current_dir == 'asc' ? t(label_key) : t(reverse_label_key) |
| 71 | + else |
| 72 | + t(label_key) |
| 73 | + end |
| 74 | + dir = if is_current |
| 75 | + current_dir == 'asc' ? 'desc' : 'asc' |
| 76 | + else |
| 77 | + # Defaults: az -> asc, others -> desc |
| 78 | + key == 'az' ? 'asc' : 'desc' |
| 79 | + end |
| 80 | + link_to label, users_path(sort: key, dir: dir, location: filters[:location], company: filters[:company]), class: "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:bg-gray-100 focus:text-gray-900 focus:outline-none cursor-pointer" |
| 81 | + end %> |
| 82 | + |
| 83 | + <%= sort_link('users.index.sort.top', 'users.index.sort.top_reverse', 'top', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 84 | + <%= sort_link('users.index.sort.new', 'users.index.sort.new_reverse', 'new', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 85 | + <%= sort_link('users.index.sort.projects', 'users.index.sort.projects_reverse', 'projects', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 86 | + <%= sort_link('users.index.sort.posts', 'users.index.sort.posts_reverse', 'posts', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 87 | + <%= sort_link('users.index.sort.comments', 'users.index.sort.comments_reverse', 'comments', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 88 | + <%= sort_link('users.index.sort.stars', 'users.index.sort.stars_reverse', 'stars', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 89 | + <%= sort_link('users.index.sort.az', 'users.index.sort.az_reverse', 'az', @sort, @dir, { location: @filter_location, company: @filter_company }) %> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </div> |
36 | 94 |
|
37 | 95 | <!-- Active Filters --> |
38 | 96 | <% if @filter_location.present? || @filter_company.present? %> |
|
0 commit comments