diff --git a/lib/microwaveprop_web/live/rover_live.ex b/lib/microwaveprop_web/live/rover_live.ex index ad758dc8..a6095041 100644 --- a/lib/microwaveprop_web/live/rover_live.ex +++ b/lib/microwaveprop_web/live/rover_live.ex @@ -209,7 +209,8 @@ defmodule MicrowavepropWeb.RoverLive do {:ok, stations} -> {:noreply, socket - |> assign(fixed_stations: stations, station_form_error: nil) + |> assign_stations(stations) + |> assign(station_form_error: nil) |> sync_url()} {:error, msg} -> @@ -236,7 +237,8 @@ defmodule MicrowavepropWeb.RoverLive do {:ok, stations} -> {:noreply, socket - |> assign(fixed_stations: stations, station_form_error: nil) + |> assign_stations(stations) + |> assign(station_form_error: nil) |> sync_url()} {:error, msg} -> @@ -344,13 +346,19 @@ defmodule MicrowavepropWeb.RoverLive do defp handle_station_mutation(socket, id, fun) do case fun.(socket, id) do {:ok, stations} -> - {:noreply, socket |> assign(fixed_stations: stations) |> sync_url()} + {:noreply, socket |> assign_stations(stations) |> sync_url()} {:error, _} -> {:noreply, socket} end end + defp assign_stations(socket, stations) do + socket + |> assign(fixed_stations: stations) + |> push_event("stations_updated", %{stations: stations_for_compute(stations)}) + end + defp sync_url(socket) do push_patch(socket, to: rover_path(socket), replace: true) end