defmodule MusicLibraryWeb.StatsComponents do use MusicLibraryWeb, :live_component import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1, artist_links: 1] alias MusicLibrary.Records attr :record, Records.Record, required: true attr :title, :string, required: true attr :class, :string def album_preview(assigns) do ~H"""
{@title}
{@record.title} <.link :for={artist <- @record.artists} class="text-sm md:text-base text-zinc-600 dark:text-zinc-200 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" navigate={~p"/artists/#{artist.musicbrainz_id}"} > {artist.name}
{@title}
{format_label(record.format)} · {type_label(record.type)} · {gettext("Purchased on")} <.icon name="hero-banknotes" class="-mt-1 h-4 w-4" aria-hidden="true" data-slot="icon" /> {Records.Record.format_as_date(record.purchased_at)} · {gettext("Wishlisted on")} <.icon name="hero-star" class="-mt-1 h-4 w-4" aria-hidden="true" data-slot="icon" /> {Records.Record.format_as_date(record.inserted_at)}
{ngettext( "1 year ago", "%{count} years ago", @years )}
""" end defp special_year?(year) when year in [5, 10, 25, 50, 75], do: true defp special_year?(_year), do: false def tracked_record?(tracked_releases, release_id) do Enum.find_value(tracked_releases, fn tracked_release -> if tracked_release.release_id == release_id, do: tracked_release.record_id end) end # The Tailwind build step requires all needed classes to be explicitly referenced # in the source code, and not dynamically generated. This implies that one cannot # (for example) interpolate a number in a class name. defp stats_class(collection) do case Enum.count(collection) do 1 -> "grid-cols-1" 2 -> "grid-cols-2" 3 -> "grid-cols-3" 4 -> "grid-cols-4" 5 -> "grid-cols-5" 6 -> "grid-cols-6" 7 -> "grid-cols-7" 8 -> "grid-cols-8" 9 -> "grid-cols-9" _other -> "" end end end