fix(rover): push stations_updated to map hook on add/edit/toggle/delete
This commit is contained in:
parent
915cd1f5a0
commit
9178751bac
1 changed files with 11 additions and 3 deletions
|
|
@ -209,7 +209,8 @@ defmodule MicrowavepropWeb.RoverLive do
|
||||||
{:ok, stations} ->
|
{:ok, stations} ->
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(fixed_stations: stations, station_form_error: nil)
|
|> assign_stations(stations)
|
||||||
|
|> assign(station_form_error: nil)
|
||||||
|> sync_url()}
|
|> sync_url()}
|
||||||
|
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
|
|
@ -236,7 +237,8 @@ defmodule MicrowavepropWeb.RoverLive do
|
||||||
{:ok, stations} ->
|
{:ok, stations} ->
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(fixed_stations: stations, station_form_error: nil)
|
|> assign_stations(stations)
|
||||||
|
|> assign(station_form_error: nil)
|
||||||
|> sync_url()}
|
|> sync_url()}
|
||||||
|
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
|
|
@ -344,13 +346,19 @@ defmodule MicrowavepropWeb.RoverLive do
|
||||||
defp handle_station_mutation(socket, id, fun) do
|
defp handle_station_mutation(socket, id, fun) do
|
||||||
case fun.(socket, id) do
|
case fun.(socket, id) do
|
||||||
{:ok, stations} ->
|
{:ok, stations} ->
|
||||||
{:noreply, socket |> assign(fixed_stations: stations) |> sync_url()}
|
{:noreply, socket |> assign_stations(stations) |> sync_url()}
|
||||||
|
|
||||||
{:error, _} ->
|
{:error, _} ->
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
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
|
defp sync_url(socket) do
|
||||||
push_patch(socket, to: rover_path(socket), replace: true)
|
push_patch(socket, to: rover_path(socket), replace: true)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue