use initial ammo group form component select state
This commit is contained in:
parent
3adb8c9aae
commit
7464947497
@ -22,14 +22,23 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
|
||||
|
||||
@spec update(Socket.t()) :: {:ok, Socket.t()}
|
||||
def update(%{assigns: %{current_user: current_user}} = socket) do
|
||||
socket =
|
||||
%{assigns: %{ammo_types: ammo_types, containers: containers}} = socket =
|
||||
socket
|
||||
|> assign(:ammo_group_create_limit, @ammo_group_create_limit)
|
||||
|> assign_changeset(%{})
|
||||
|> assign(:ammo_types, Ammo.list_ammo_types(current_user))
|
||||
|> assign_new(:containers, fn -> Containers.list_containers(current_user) end)
|
||||
|
||||
{:ok, socket}
|
||||
params =
|
||||
if ammo_types |> List.first() |> is_nil(),
|
||||
do: %{},
|
||||
else: %{} |> Map.put("ammo_type_id", ammo_types |> List.first() |> Map.get(:id))
|
||||
|
||||
params =
|
||||
if containers |> List.first() |> is_nil(),
|
||||
do: params,
|
||||
else: params |> Map.put("container_id", containers |> List.first() |> Map.get(:id))
|
||||
|
||||
{:ok, socket |> assign_changeset(params)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
Loading…
Reference in New Issue
Block a user