use initial ammo group form component select state
This commit is contained in:
		| @@ -22,14 +22,23 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do | |||||||
|  |  | ||||||
|   @spec update(Socket.t()) :: {:ok, Socket.t()} |   @spec update(Socket.t()) :: {:ok, Socket.t()} | ||||||
|   def update(%{assigns: %{current_user: current_user}} = socket) do |   def update(%{assigns: %{current_user: current_user}} = socket) do | ||||||
|     socket = |     %{assigns: %{ammo_types: ammo_types, containers: containers}} = socket = | ||||||
|       socket |       socket | ||||||
|       |> assign(:ammo_group_create_limit, @ammo_group_create_limit) |       |> assign(:ammo_group_create_limit, @ammo_group_create_limit) | ||||||
|       |> assign_changeset(%{}) |  | ||||||
|       |> assign(:ammo_types, Ammo.list_ammo_types(current_user)) |       |> assign(:ammo_types, Ammo.list_ammo_types(current_user)) | ||||||
|       |> assign_new(:containers, fn -> Containers.list_containers(current_user) end) |       |> 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 |   end | ||||||
|  |  | ||||||
|   @impl true |   @impl true | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user