From 84fff2e9fbd97ae0704d6a5eb906043cbf40b94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 7 Mar 2023 18:45:15 +0100 Subject: [PATCH] Simplify code setting marker data in maps We were probably setting them separately to avoid having blank data attributes in the HTML. However, when a data attribute is `nil`, Rails doesn't write it in the HTML in the first place. --- app/components/shared/map_location_component.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/components/shared/map_location_component.rb b/app/components/shared/map_location_component.rb index 693589541..c0f88831d 100644 --- a/app/components/shared/map_location_component.rb +++ b/app/components/shared/map_location_component.rb @@ -44,7 +44,7 @@ class Shared::MapLocationComponent < ApplicationComponent end def data - options = { + { map: "", map_center_latitude: latitude, map_center_longitude: longitude, @@ -56,10 +56,9 @@ class Shared::MapLocationComponent < ApplicationComponent latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}", - marker_investments_coordinates: investments_coordinates + marker_investments_coordinates: investments_coordinates, + marker_latitude: map_location.latitude.presence, + marker_longitude: map_location.longitude.presence } - options[:marker_latitude] = map_location.latitude if map_location.latitude.present? - options[:marker_longitude] = map_location.longitude if map_location.longitude.present? - options end end