fix foci form component to do normalization there, fixes the AQI queries too

f36797b · gmorell · 2022-09-17 08:52

7 files +8 -1

Files changed

modified apps/room_sanctum/lib/room_sanctum_web/live/cfg_foci_live/form_component.ex
+8 −1
@@ -8,6 +8,13 @@ defmodule RoomSanctumWeb.FociLive.FormComponent do
8 8 |> Map.put("user_id", socket.assigns.current_user.id)
9 9 end
10 10
11 + defp normalize_ll(val) do
12 + cond do
13 + val < -180 -> val+360
14 + true -> val
15 + end
16 + end
17 +
11 18 @impl true
12 19 def update(%{foci: foci} = assigns, socket) do
13 20 changeset = Configuration.change_foci(foci)
@@ -51,7 +58,7 @@ defmodule RoomSanctumWeb.FociLive.FormComponent do
51 58 end
52 59
53 60 def handle_event("map-update", %{"latlng" => latlng}, socket) do
54 − lat_lng_pt = %Geo.Point{coordinates: {latlng["lat"], latlng["lng"]}, srid: 4326}
61 + lat_lng_pt = %Geo.Point{coordinates: {latlng["lat"] |> normalize_ll, latlng["lng"] |> normalize_ll}, srid: 4326}
55 62 cs = socket.assigns.changeset |> Ecto.Changeset.change(place: lat_lng_pt)
56 63 # |> Map.put(:action, :validate)
57 64 # cs = socket.assigns.foci |> Configuration.change_foci(%{place: lat_lng_pt}) |> Map.put(:action, :validate)

Parents: f8b0060