diff --git a/lib/music_library/collection.ex b/lib/music_library/collection.ex index 2c68ecad..50073284 100644 --- a/lib/music_library/collection.ex +++ b/lib/music_library/collection.ex @@ -40,6 +40,19 @@ defmodule MusicLibrary.Collection do Repo.all(q) end + def get_records_on_this_day(date \\ Date.utc_today()) do + month_day = Calendar.strftime(date, "%m-%d") + + q = + from r in Record, + where: not is_nil(r.purchased_at), + where: fragment("strftime('%m-%d', ?) = ?", r.release_date, ^month_day), + order_by: [desc: r.release_date], + select: ^Records.essential_fields() + + Repo.all(q) + end + def get_latest_record! do q = from r in Record, diff --git a/lib/music_library_web/components/stats_components.ex b/lib/music_library_web/components/stats_components.ex index 972125c9..b091454b 100644 --- a/lib/music_library_web/components/stats_components.ex +++ b/lib/music_library_web/components/stats_components.ex @@ -1,7 +1,11 @@ defmodule MusicLibraryWeb.StatsComponents do use MusicLibraryWeb, :live_component - attr :record, MusicLibrary.Records.Record, required: true + 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 @@ -79,6 +83,88 @@ defmodule MusicLibraryWeb.StatsComponents do """ end + attr :record_show_path, :any, required: true + attr :records, :list, required: true + attr :current_date, Date, required: false, default: nil + + def records_on_this_day(assigns) do + ~H""" +
+ {Records.Record.format_release_date(record.release_date)} + + ({gettext("Unreleased")}) + +
++ {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)} + +
+