Skip to content

Commit

Permalink
Always show the communities you belong to.
Browse files Browse the repository at this point in the history
Parameterize the "critical_mass" (number of members needed before the community is displayed).

0260

Adapt tests for recent feature of showing only communities with more than 2 members.
  • Loading branch information
openbrian committed Mar 24, 2023
1 parent ad0991f commit a14209b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def index
.group("communities.id")
.having("COUNT(communities.id) > #{@critical_mass}")
.order(Arel.sql(sunniest_communities))

@my_communities = current_user ? current_user.communities : []
end

# GET /communities/mycity
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class User < ApplicationRecord
has_many :reports

has_many :communities_lead, :class_name => "Community", :foreign_key => :leader_id, :inverse_of => :leader
has_many :community_members
has_many :communities, :through => :community_members

scope :visible, -> { where(:status => %w[pending active confirmed]) }
scope :active, -> { where(:status => %w[active confirmed]) }
Expand Down
3 changes: 3 additions & 0 deletions app/views/communities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
<%= render :partial => "index_list", :locals => { :communities => @communities_lead, :header => t(".communities_lead") } %>
<% end %>

<%= render :partial => "index_list", :locals => { :communities => @my_communities, :header => t(".my_communities") } %>

<p>
<%= t(".sorted_by") %>
<%= t(".critical_mass", :n => @critical_mass) %>
</p>

<%= render :partial => "index_list", :locals => { :communities => @all_communities, :header => t(".all") } %>
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,10 @@ en:
edit_community: "Edit Community"
index:
all: "All Communities"
longitude: "Longitude"
communities_lead: "Communities Lead"
critical_mass: "Only communities with %{n} members are displayed."
longitude: "Longitude"
my_communities: "My Communities"
new: "New"
new_title: "Create a new community"
sorted_by: "Sorted by longitude and time of day."
Expand Down

0 comments on commit a14209b

Please sign in to comment.