From a6a9994b97c3ce75eab52c74c2ac099191114a21 Mon Sep 17 00:00:00 2001 From: shibao Date: Tue, 1 Feb 2022 00:14:14 -0500 Subject: [PATCH] style ammo group index page --- lib/cannery_web/live/ammo_group_live/index.ex | 13 ++--- .../live/ammo_group_live/index.html.heex | 57 +++++++++++++++++++ .../live/ammo_group_live/index.html.leex | 39 ------------- 3 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 lib/cannery_web/live/ammo_group_live/index.html.heex delete mode 100644 lib/cannery_web/live/ammo_group_live/index.html.leex diff --git a/lib/cannery_web/live/ammo_group_live/index.ex b/lib/cannery_web/live/ammo_group_live/index.ex index 33952f0..5cc2fe1 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 0000000..a589392 --- /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" %> + +
+ + + + + + + + + + + + <%= for ammo_group <- @ammo_groups do %> + + + + + + + + <% end %> + +
CountPrice paidNotes
<%= 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 %> +
+ +<%= 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 e1eb555..0000000 --- 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 %> - - - - - - - - - - - - - <%= for ammo_group <- @ammo_groups do %> - - - - - - - - <% end %> - -
CountPrice paidNotes
<%= 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?"] %> -
- -<%= live_patch "New Ammo group", to: Routes.ammo_group_index_path(@socket, :new) %>