diff --git a/lib/cannery_web/live/ammo_group_live/index.ex b/lib/cannery_web/live/ammo_group_live/index.ex
index 33952f0f..5cc2fe1b 100644
--- a/lib/cannery_web/live/ammo_group_live/index.ex
+++ b/lib/cannery_web/live/ammo_group_live/index.ex
@@ -10,7 +10,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
@impl true
def mount(_params, session, socket) do
- {:ok, socket |> assign_defaults(session) |> assign(:ammo_groups, list_ammo_groups())}
+ {:ok, socket |> assign_defaults(session) |> display_ammo_groups()}
end
@impl true
@@ -38,13 +38,12 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
@impl true
def handle_event("delete", %{"id" => id}, socket) do
- ammo_group = Ammo.get_ammo_group!(id)
- {:ok, _} = Ammo.delete_ammo_group(ammo_group)
-
- {:noreply, socket |> assign(:ammo_groups, list_ammo_groups())}
+ Ammo.get_ammo_group!(id) |> Ammo.delete_ammo_group!()
+ {:noreply, socket |> display_ammo_groups()}
end
- defp list_ammo_groups do
- Ammo.list_ammo_groups()
+ defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
+ ammo_groups = Ammo.list_ammo_groups(current_user)
+ socket |> assign(:ammo_groups, ammo_groups)
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
new file mode 100644
index 00000000..a589392d
--- /dev/null
+++ b/lib/cannery_web/live/ammo_group_live/index.html.heex
@@ -0,0 +1,57 @@
+
+
+ Listing Ammo
+
+
+ <%= if @ammo_groups |> Enum.empty?() do %>
+
+ No Ammo 😔
+
+
+ <%= live_patch "Add your first box!",
+ to: Routes.ammo_group_index_path(@socket, :new),
+ class: "btn btn-primary" %>
+ <% else %>
+ <%= live_patch "New Ammo group",
+ to: Routes.ammo_group_index_path(@socket, :new),
+ class: "btn btn-primary" %>
+
+
+
+
+
+ Count |
+ Price paid |
+ Notes |
+
+ |
+
+
+
+ <%= for ammo_group <- @ammo_groups do %>
+
+ <%= ammo_group.count %> |
+ <%= ammo_group.price_paid %> |
+ <%= ammo_group.notes %> |
+
+
+ <%= live_redirect "Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group) %>
+ <%= live_patch "Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group) %>
+ <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: ammo_group.id, data: [confirm: "Are you sure?"] %>
+ |
+
+ <% end %>
+
+
+
+ <% end %>
+
+
+<%= if @live_action in [:new, :edit] do %>
+ <%= live_modal CanneryWeb.AmmoGroupLive.FormComponent,
+ id: @ammo_group.id || :new,
+ title: @page_title,
+ action: @live_action,
+ ammo_group: @ammo_group,
+ return_to: Routes.ammo_group_index_path(@socket, :index) %>
+<% end %>
diff --git a/lib/cannery_web/live/ammo_group_live/index.html.leex b/lib/cannery_web/live/ammo_group_live/index.html.leex
deleted file mode 100644
index e1eb5559..00000000
--- a/lib/cannery_web/live/ammo_group_live/index.html.leex
+++ /dev/null
@@ -1,39 +0,0 @@
-Listing Ammo groups
-
-<%= if @live_action in [:new, :edit] do %>
- <%= live_modal CanneryWeb.AmmoGroupLive.FormComponent,
- id: @ammo_group.id || :new,
- title: @page_title,
- action: @live_action,
- ammo_group: @ammo_group,
- return_to: Routes.ammo_group_index_path(@socket, :index) %>
-<% end %>
-
-
-
-
- Count |
- Price paid |
- Notes |
-
- |
-
-
-
- <%= for ammo_group <- @ammo_groups do %>
-
- <%= ammo_group.count %> |
- <%= ammo_group.price_paid %> |
- <%= ammo_group.notes %> |
-
-
- <%= live_redirect "Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group) %>
- <%= live_patch "Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group) %>
- <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: ammo_group.id, data: [confirm: "Are you sure?"] %>
- |
-
- <% end %>
-
-
-
-<%= live_patch "New Ammo group", to: Routes.ammo_group_index_path(@socket, :new) %>