defmodule MusicLibraryWeb.StatsComponents do use MusicLibraryWeb, :live_component import MusicLibraryWeb.RecordComponents, only: [ format_label: 1, type_label: 1, artist_links: 1, record_cover: 1, release_groups_badge: 1 ] alias MusicLibrary.Records attr :record, Records.Record, required: false attr :title, :string, required: true attr :class, :string def album_preview(assigns) do ~H"""
<.record_cover record={@record} class="w-20 md:w-24 rounded-md shadow-sm" width={192} />

{@title}

{@record.title} <.link :for={artist <- @record.artists} class="text-sm md:text-base text-zinc-600 dark:text-zinc-300 hover:text-zinc-500 dark:hover:text-zinc-200" navigate={~p"/artists/#{artist.musicbrainz_id}"} > {artist.name}

{gettext("No record found")}

""" end attr :title, :string, required: true attr :count, :integer, required: true attr :path, :string, required: false, default: nil attr :tooltip, :any, required: false, default: nil def counter(assigns) do ~H"""

{@title}

<.link :if={@path} navigate={@path} class="block text-2xl sm:text-3xl font-semibold text-center text-zinc-900 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" > {@count}

{@count}

<.tooltip> <:content> {@tooltip} <.link :if={@path} navigate={@path} class="block text-2xl sm:text-3xl font-semibold text-center text-zinc-900 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" > {@count}

{@count}

""" end attr :categories_with_counts, :list, required: true attr :category_format_fn, :any, required: true attr :category_path_fn, :any, required: true def counters_by_category(assigns) do ~H"""
{@category_format_fn.(category)}
<.link class="text-xl lg:text-2xl font-semibold hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" navigate={@category_path_fn.(category)} > {count}
""" end attr :record_show_path, :any, required: true attr :records, :list, required: true attr :current_date, Date, required: true def records_on_this_day(assigns) do ~H""" """ end attr :record, Records.Record, required: true attr :current_date, Date, required: true defp released_how_long_ago(assigns) do assigns = assign( assigns, :years, Records.Record.released_how_long_ago?(assigns.record, assigns.current_date) ) ~H""" {gettext("Today")} {ngettext( "1 year ago", "%{count} years ago", @years )} """ end defp same_year?(year), do: year == 0 defp gold_year?(year), do: rem(year, 10) == 0 defp silver_year?(year), do: rem(year, 5) == 0 defp normal_year?(year), do: !gold_year?(year) && !silver_year?(year) # 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