We had similar conditions many times and some duplication, particularly between the code getting records and the code counting records. We can remove it by returning a generic scope and calling the `count` method to count the records and the `order` and `page` methods when we want to pass the records to the view. And, since we only display one partial per request, we can simplify the code to render all the partials. There's one minor disadvantage to this approach: searching the code for the place where these partials are rendered is now a bit harder since searching the code for something like "render (.+) budget_investments" won't return any results. We're also writing conditions about a certain filter just once, by setting `valid_filters`. This greatly simplifies the logic, although again there's one minor disadvantage: we have to implement the `current_filter` method, duplicating the logic already defined in the `HasFilters` concern.
33 lines
1008 B
Plaintext
33 lines
1008 B
Plaintext
<% if valid_access? %>
|
|
<% if valid_filters.any? %>
|
|
<ul class="menu simple margin-top">
|
|
<% valid_filters.each do |filter| %>
|
|
<% if current_filter == filter %>
|
|
<li class="is-active">
|
|
<h2><%= t("users.show.filters.#{filter}", count: count(filter)) %></h2>
|
|
</li>
|
|
<% else %>
|
|
<li>
|
|
<%= link_to t("users.show.filters.#{filter}", count: count(filter)),
|
|
current_path_with_query_params(filter: filter, page: 1) %>
|
|
</li>
|
|
<% end %>
|
|
<% end %>
|
|
</ul>
|
|
|
|
<% if current_filter == "follows" %>
|
|
<%= render "users/following", user: user, follows: follows.group_by(&:followable_type) %>
|
|
<% else %>
|
|
<%= render_user_partial current_filter %>
|
|
<% end %>
|
|
<% else %>
|
|
<div class="callout primary">
|
|
<%= t("users.show.no_activity") %>
|
|
</div>
|
|
<% end %>
|
|
<% else %>
|
|
<div class="callout warning margin">
|
|
<%= t("users.show.private_activity") %>
|
|
</div>
|
|
<% end %>
|