Move users following partial to a component

This commit is contained in:
Javi Martín
2024-10-23 00:46:48 +02:00
parent c4d69416ca
commit 909272d879
6 changed files with 67 additions and 58 deletions

View File

@@ -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
// -------------------

View 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;
}
}
}

View File

@@ -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>
<ul class="menu simple clear">
<% follows.each do |followable_type, follows| %>

View 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

View File

@@ -16,7 +16,7 @@
</ul>
<% 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 %>
<%= render_user_partial current_filter %>
<% end %>

View File

@@ -1,26 +1,4 @@
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)
Follow.find_or_initialize_by(user: user, followable: followable)
end