diff --git a/app/components/budgets/investments/map_component.html.erb b/app/components/budgets/investments/map_component.html.erb
new file mode 100644
index 000000000..2324476b8
--- /dev/null
+++ b/app/components/budgets/investments/map_component.html.erb
@@ -0,0 +1,3 @@
+
+ <%= render_map(map_location, investments_coordinates: coordinates) %>
+
diff --git a/app/components/budgets/investments/map_component.rb b/app/components/budgets/investments/map_component.rb
new file mode 100644
index 000000000..7c88ac828
--- /dev/null
+++ b/app/components/budgets/investments/map_component.rb
@@ -0,0 +1,22 @@
+class Budgets::Investments::MapComponent < ApplicationComponent
+ attr_reader :heading, :investments
+
+ def initialize(investments, heading:)
+ @investments = investments
+ @heading = heading
+ end
+
+ def render?
+ map_location&.available?
+ end
+
+ private
+
+ def map_location
+ MapLocation.from_heading(heading) if heading.present?
+ end
+
+ def coordinates
+ MapLocation.where(investment: investments).map(&:json_data)
+ end
+end
diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index ca9a18d0c..84277042f 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -20,7 +20,6 @@ module Budgets
before_action :load_ballot, only: [:index, :show]
before_action :load_heading, only: [:index, :show]
- before_action :load_map, only: [:index]
before_action :set_random_seed, only: :index
before_action :load_categories, only: :index
before_action :set_default_investment_filter, only: :index
@@ -41,10 +40,9 @@ module Budgets
def index
@investments = investments.page(params[:page]).per(PER_PAGE).for_render
-
@investment_ids = @investments.ids
- @investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data)
+ @investments_in_map = investments
@tag_cloud = tag_cloud
@remote_translations = detect_remote_translations(@investments)
end
@@ -179,9 +177,5 @@ module Budgets
params[:filter] ||= "selected"
end
end
-
- def load_map
- @map_location = MapLocation.from_heading(@heading) if @heading.present?
- end
end
end
diff --git a/app/views/budgets/investments/_map.html.erb b/app/views/budgets/investments/_map.html.erb
deleted file mode 100644
index be68bcdbe..000000000
--- a/app/views/budgets/investments/_map.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= render_map(@map_location, investments_coordinates: @investments_map_coordinates) %>
-
diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb
index a45ea333f..9aba3eeb1 100644
--- a/app/views/budgets/investments/_sidebar.html.erb
+++ b/app/views/budgets/investments/_sidebar.html.erb
@@ -22,10 +22,7 @@
<%= render Budgets::Investments::ContentBlocksComponent.new(@heading) %>
-
-<% if @map_location&.available? %>
- <%= render "budgets/investments/map" %>
-<% end %>
+<%= render Budgets::Investments::MapComponent.new(@investments_in_map, heading: @heading) %>
<%= render "shared/tag_cloud", taggable: "Budget::Investment" %>
<%= render "budgets/investments/categories" %>
<%= render Budgets::Investments::FiltersComponent.new %>