Move users following partial to a component
This commit is contained in:
@@ -1857,40 +1857,6 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.following {
|
|
||||||
|
|
||||||
.follow-list {
|
|
||||||
list-style-type: circle;
|
|
||||||
padding: calc($line-height / 2);
|
|
||||||
|
|
||||||
li {
|
|
||||||
margin-bottom: calc($line-height / 2);
|
|
||||||
margin-left: $line-height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: rem-calc(24);
|
|
||||||
margin-top: $line-height;
|
|
||||||
padding-left: rem-calc(30);
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
span {
|
|
||||||
left: 0;
|
|
||||||
position: absolute;
|
|
||||||
top: 2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.interests {
|
|
||||||
|
|
||||||
@include breakpoint(medium) {
|
|
||||||
border-left: 1px solid #ececec;
|
|
||||||
padding-left: $line-height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 19. Recommendations
|
// 19. Recommendations
|
||||||
// -------------------
|
// -------------------
|
||||||
|
|
||||||
|
|||||||
33
app/assets/stylesheets/users/following.scss
Normal file
33
app/assets/stylesheets/users/following.scss
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
.users-following {
|
||||||
|
|
||||||
|
.follow-list {
|
||||||
|
list-style-type: circle;
|
||||||
|
padding: calc($line-height / 2);
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: calc($line-height / 2);
|
||||||
|
margin-left: $line-height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: rem-calc(24);
|
||||||
|
margin-top: $line-height;
|
||||||
|
padding-left: rem-calc(30);
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
span {
|
||||||
|
left: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.interests {
|
||||||
|
|
||||||
|
@include breakpoint(medium) {
|
||||||
|
border-left: 1px solid #ececec;
|
||||||
|
padding-left: $line-height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<div class="row following margin-top" data-equalizer data-equalize-on="medium">
|
<div class="row users-following margin-top" data-equalizer data-equalize-on="medium">
|
||||||
<div class="small-12 medium-8 column" data-equalizer-watch>
|
<div class="small-12 medium-8 column" data-equalizer-watch>
|
||||||
<ul class="menu simple clear">
|
<ul class="menu simple clear">
|
||||||
<% follows.each do |followable_type, follows| %>
|
<% follows.each do |followable_type, follows| %>
|
||||||
32
app/components/users/following_component.rb
Normal file
32
app/components/users/following_component.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
class Users::FollowingComponent < ApplicationComponent
|
||||||
|
attr_reader :user, :follows
|
||||||
|
|
||||||
|
def initialize(user, follows:)
|
||||||
|
@user = user
|
||||||
|
@follows = follows
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def followable_type_title(followable_type)
|
||||||
|
t("activerecord.models.#{followable_type.underscore}.other")
|
||||||
|
end
|
||||||
|
|
||||||
|
def followable_icon(followable)
|
||||||
|
{ proposals: "Proposal", budget: "Budget::Investment" }.invert[followable]
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_follow(follow)
|
||||||
|
return if follow.followable.blank?
|
||||||
|
|
||||||
|
followable = follow.followable
|
||||||
|
partial = "#{followable_class_name(followable)}_follow"
|
||||||
|
locals = { followable_class_name(followable).to_sym => followable }
|
||||||
|
|
||||||
|
render partial, locals
|
||||||
|
end
|
||||||
|
|
||||||
|
def followable_class_name(followable)
|
||||||
|
followable.class.to_s.parameterize(separator: "_")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<% if current_filter == "follows" %>
|
<% if current_filter == "follows" %>
|
||||||
<%= render "users/following", user: user, follows: follows.group_by(&:followable_type) %>
|
<%= render Users::FollowingComponent.new(user, follows: follows.group_by(&:followable_type)) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render_user_partial current_filter %>
|
<%= render_user_partial current_filter %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,26 +1,4 @@
|
|||||||
module FollowablesHelper
|
module FollowablesHelper
|
||||||
def followable_type_title(followable_type)
|
|
||||||
t("activerecord.models.#{followable_type.underscore}.other")
|
|
||||||
end
|
|
||||||
|
|
||||||
def followable_icon(followable)
|
|
||||||
{ proposals: "Proposal", budget: "Budget::Investment" }.invert[followable]
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_follow(follow)
|
|
||||||
return if follow.followable.blank?
|
|
||||||
|
|
||||||
followable = follow.followable
|
|
||||||
partial = "#{followable_class_name(followable)}_follow"
|
|
||||||
locals = { followable_class_name(followable).to_sym => followable }
|
|
||||||
|
|
||||||
render partial, locals
|
|
||||||
end
|
|
||||||
|
|
||||||
def followable_class_name(followable)
|
|
||||||
followable.class.to_s.parameterize(separator: "_")
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_or_build_follow(user, followable)
|
def find_or_build_follow(user, followable)
|
||||||
Follow.find_or_initialize_by(user: user, followable: followable)
|
Follow.find_or_initialize_by(user: user, followable: followable)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user