diff --git a/lib/cannery_web/live/ammo_group_live/index.ex b/lib/cannery_web/live/ammo_group_live/index.ex index 0a030d8c..d7e6eed0 100644 --- a/lib/cannery_web/live/ammo_group_live/index.ex +++ b/lib/cannery_web/live/ammo_group_live/index.ex @@ -4,7 +4,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do """ use CanneryWeb, :live_view - alias Cannery.{Ammo, Ammo.AmmoGroup, Repo} + alias Cannery.{Ammo, Ammo.AmmoGroup, Containers, Repo} alias CanneryWeb.Endpoint @impl true @@ -17,9 +17,11 @@ defmodule CanneryWeb.AmmoGroupLive.Index do {:noreply, apply_action(socket, live_action, params)} end - defp apply_action(%{assigns: %{current_user: current_user}} = socket, :add_shot_group, %{ - "id" => id - }) do + defp apply_action( + %{assigns: %{current_user: current_user}} = socket, + :add_shot_group, + %{"id" => id} + ) do socket |> assign(:page_title, gettext("Record shots")) |> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user)) @@ -72,6 +74,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container]) - socket |> assign(:ammo_groups, ammo_groups) + containers = Containers.list_containers(current_user) + socket |> assign(ammo_groups: ammo_groups, containers: containers) end end diff --git a/lib/cannery_web/live/ammo_group_live/index.html.heex b/lib/cannery_web/live/ammo_group_live/index.html.heex index c2fab220..a4b59a2a 100644 --- a/lib/cannery_web/live/ammo_group_live/index.html.heex +++ b/lib/cannery_web/live/ammo_group_live/index.html.heex @@ -9,15 +9,41 @@ <%= display_emoji("😔") %> - <%= live_patch(dgettext("actions", "Add your first box!"), - to: Routes.ammo_group_index_path(Endpoint, :new), - class: "btn btn-primary" - ) %> + <%= if @containers |> Enum.empty?() do %> +