cannery/lib/cannery_web/components/container_card.ex

82 lines
2.5 KiB
Elixir
Raw Normal View History

2022-02-11 22:47:33 -05:00
defmodule CanneryWeb.Components.ContainerCard do
2022-02-05 01:59:40 -05:00
@moduledoc """
Display card for a container
"""
use CanneryWeb, :component
2022-02-18 22:56:46 -05:00
import CanneryWeb.Components.TagCard
2022-11-09 21:18:29 -05:00
alias Cannery.{Containers, Containers.Container, Repo}
2022-02-05 01:59:40 -05:00
alias CanneryWeb.Endpoint
2022-11-09 21:18:29 -05:00
alias Phoenix.LiveView.Rendered
2022-02-05 01:59:40 -05:00
2022-11-09 21:18:29 -05:00
attr :container, Container, required: true
slot(:tag_actions)
slot(:inner_block)
@spec container_card(assigns :: map()) :: Rendered.t()
2022-02-18 22:56:46 -05:00
def container_card(%{container: container} = assigns) do
2022-11-09 21:18:29 -05:00
assigns =
assigns
|> assign(container: container |> Repo.preload([:tags, :ammo_groups]))
|> assign_new(:tag_actions, fn -> [] end)
2022-02-18 22:56:46 -05:00
2022-02-05 01:59:40 -05:00
~H"""
<div
id={"container-#{@container.id}"}
2023-02-04 10:28:13 -05:00
class="overflow-hidden max-w-full mx-4 mb-4 px-8 py-4
flex flex-col justify-center items-center space-y-4
2022-02-15 23:20:18 -05:00
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
2022-02-05 01:59:40 -05:00
>
2022-03-28 23:56:45 -04:00
<div class="max-w-full mb-4 flex flex-col justify-center items-center space-y-2">
<.link navigate={Routes.container_show_path(Endpoint, :show, @container)} class="link">
2022-02-05 01:59:40 -05:00
<h1 class="px-4 py-2 rounded-lg title text-xl">
<%= @container.name %>
</h1>
</.link>
2022-02-05 01:59:40 -05:00
2023-02-04 10:28:13 -05:00
<span :if={@container.desc} class="rounded-lg title text-lg">
<%= gettext("Description:") %>
<%= @container.desc %>
</span>
2022-02-05 01:59:40 -05:00
<span class="rounded-lg title text-lg">
2022-02-09 00:49:47 -05:00
<%= gettext("Type:") %>
<%= @container.type %>
2022-02-05 01:59:40 -05:00
</span>
2023-02-04 10:28:13 -05:00
<span :if={@container.location} class="rounded-lg title text-lg">
<%= gettext("Location:") %>
<%= @container.location %>
</span>
2022-02-18 22:56:46 -05:00
2022-07-01 19:13:54 -04:00
<%= unless @container.ammo_groups |> Enum.empty?() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Containers.get_container_ammo_group_count!() %>
</span>
2022-02-18 22:56:46 -05:00
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>
</span>
<% end %>
<div class="flex flex-wrap justify-center items-center">
2023-02-04 10:28:13 -05:00
<.simple_tag_card :for={tag <- @container.tags} :if={@container.tags} tag={tag} />
2022-02-18 22:56:46 -05:00
2022-11-09 21:18:29 -05:00
<%= render_slot(@tag_actions) %>
2022-02-18 22:56:46 -05:00
</div>
2022-02-05 01:59:40 -05:00
</div>
2023-02-04 10:28:13 -05:00
<div
:if={assigns |> Map.has_key?(:inner_block)}
class="flex space-x-4 justify-center items-center"
>
<%= render_slot(@inner_block) %>
</div>
2022-02-05 01:59:40 -05:00
</div>
"""
end
end