Skip to content

Commit

Permalink
refactor(shuttles): consolidate shuttle_params and validate
Browse files Browse the repository at this point in the history
  • Loading branch information
meagharty committed Jan 10, 2025
1 parent 7cec827 commit e36bba5
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions lib/arrow_web/live/shuttle_live/shuttle_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,14 @@ defmodule ArrowWeb.ShuttleViewLive do
{:ok, socket}
end

def handle_event("validate", params, socket) do
validate(params, socket)
def handle_event("validate", %{"shuttle" => shuttle_params}, socket) do
change = Shuttles.change_shuttle(socket.assigns.shuttle, shuttle_params)
form = to_form(change, action: :validate)

{:noreply, socket |> assign(form: form) |> update_map(change)}
end

def handle_event("edit", params, socket) do
shuttle_params = params["shuttle"]
def handle_event("edit", %{"shuttle" => shuttle_params}, socket) do
shuttle = Shuttles.get_shuttle!(socket.assigns.shuttle.id)

case Shuttles.update_shuttle(shuttle, shuttle_params) do
Expand All @@ -423,9 +425,7 @@ defmodule ArrowWeb.ShuttleViewLive do
end
end

def handle_event("create", params, socket) do
shuttle_params = params["shuttle"]

def handle_event("create", %{"shuttle" => shuttle_params}, socket) do
case Shuttles.create_shuttle(shuttle_params) do
{:ok, shuttle} ->
{:noreply,
Expand Down Expand Up @@ -669,15 +669,6 @@ defmodule ArrowWeb.ShuttleViewLive do
assign(socket, :map_props, %{layers: layers})
end

defp validate(params, socket) do
shuttle_params = params["shuttle"]

change = Shuttles.change_shuttle(socket.assigns.shuttle, shuttle_params)
form = to_form(change, action: :validate)

{:noreply, socket |> assign(form: form) |> update_map(change)}
end

defp handle_progress(:definition, entry, socket) do
socket = clear_flash(socket)

Expand Down

0 comments on commit e36bba5

Please sign in to comment.