diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index b7c6aedd..a390d20f 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -14,10 +14,20 @@ defmodule CanneryWeb.ContainerLive.Show do @impl true def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:container, Containers.get_container!(id))} + socket = + socket + |> assign( + page_title: page_title(socket.assigns.live_action), + container: Containers.get_container!(id) + ) + + {:noreply, socket} + end + + @impl true + def handle_event("delete", _, socket) do + socket.assigns.container |> Containers.delete_container!() + {:noreply, socket |> push_redirect(to: Routes.container_index_path(socket, :index))} end defp page_title(:show), do: "Show Container" diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex new file mode 100644 index 00000000..bf9f3a10 --- /dev/null +++ b/lib/cannery_web/live/container_live/show.html.heex @@ -0,0 +1,46 @@ +
+

+ <%= @container.name %> +

+ + <%= if @container.desc do %> + + Description: <%= @container.desc %> + + <% end %> + + + Type: <%= @container.type %> + + + <%= if @container.location do %> + + Location: <%= @container.location %> + + <% end %> + +
+ <%= live_redirect("Back", to: Routes.container_index_path(@socket, :index), class: "link") %> + <%= live_patch("Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "link") %> + <%= link("Delete", + to: "#", + class: "link", + phx_click: "delete", + data: [confirm: "Are you sure you want to delete #{@container.name}?"] + ) %> +
+ +
+ +

No ammo groups in this container

+ + <%= if @live_action in [:edit] do %> + <%= live_modal(CanneryWeb.ContainerLive.FormComponent, + id: @container.id, + title: @page_title, + action: @live_action, + container: @container, + return_to: Routes.container_show_path(@socket, :show, @container) + ) %> + <% end %> +
diff --git a/lib/cannery_web/live/container_live/show.html.leex b/lib/cannery_web/live/container_live/show.html.leex deleted file mode 100644 index 2d39aa90..00000000 --- a/lib/cannery_web/live/container_live/show.html.leex +++ /dev/null @@ -1,37 +0,0 @@ -

Show Container

- -<%= if @live_action in [:edit] do %> - <%= live_modal CanneryWeb.ContainerLive.FormComponent, - id: @container.id, - title: @page_title, - action: @live_action, - container: @container, - return_to: Routes.container_show_path(@socket, :show, @container) %> -<% end %> - - - -<%= live_patch "Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "button" %> -<%= live_redirect "Back", to: Routes.container_index_path(@socket, :index) %>