Skip to content

Commit

Permalink
fixup: format
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiejd committed Jan 16, 2025
1 parent c5b85c1 commit adca531
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions lib/arrow_web/live/shuttle_live/shuttle_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -417,38 +417,11 @@ defmodule ArrowWeb.ShuttleViewLive do
{:noreply, socket |> assign(form: form) |> update_map(change)}
end

defp update_second_direction(socket, first_direction) do
second_direction =
case first_direction do
"Inbound" -> "Outbound"
"Outbound" -> "Inbound"
"North" -> "South"
"South" -> "North"
"East" -> "West"
"West" -> "East"
end

update(socket, :form, fn %{source: changeset} ->
existing_routes = Ecto.Changeset.get_assoc(changeset, :routes)

new_routes =
Enum.map(existing_routes, fn route_changeset ->
update_route_changeset_with_new_direction_desc(route_changeset, :"1", second_direction)
end)

changeset = Ecto.Changeset.put_assoc(changeset, :routes, new_routes)

to_form(changeset)
end)
end

def handle_event(
"direction_desc_changed",
%{"shuttle" => %{"routes" => shuttle_routes}} = params,
socket
) do
IO.inspect(params)

socket =
case shuttle_routes do
%{"0" => %{"direction_desc" => first_direction}} ->
Expand Down Expand Up @@ -589,6 +562,31 @@ defmodule ArrowWeb.ShuttleViewLive do
end
end

defp update_second_direction(socket, first_direction) do
second_direction =
case first_direction do
"Inbound" -> "Outbound"
"Outbound" -> "Inbound"
"North" -> "South"
"South" -> "North"
"East" -> "West"
"West" -> "East"
end

update(socket, :form, fn %{source: changeset} ->
existing_routes = Ecto.Changeset.get_assoc(changeset, :routes)

new_routes =
Enum.map(existing_routes, fn route_changeset ->
update_route_changeset_with_new_direction_desc(route_changeset, :"1", second_direction)
end)

changeset = Ecto.Changeset.put_assoc(changeset, :routes, new_routes)

to_form(changeset)
end)
end

defp update_route_changeset_with_uploaded_stops(route_changeset, stop_ids, direction_id) do
if Ecto.Changeset.get_field(route_changeset, :direction_id) == direction_id do
new_route_stops =
Expand Down

0 comments on commit adca531

Please sign in to comment.