From 14a77c432eadbf4391ed201396c7d2889c1ee247 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 29 Aug 2025 14:47:22 +0300 Subject: [PATCH] Can set current date in stats view --- .../live/stats_live/index.ex | 15 ++++++++++++ .../live/stats_live/index.html.heex | 23 +++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index 8cf02d85..5814719b 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -81,6 +81,21 @@ defmodule MusicLibraryWeb.StatsLive.Index do |> assign(scrobble_activity_mode: mode)} end + def handle_event("set_current_date", %{"current_date" => current_date}, socket) do + case Date.from_iso8601(current_date) do + {:ok, date} -> + records_on_this_day = Collection.get_records_on_this_day(date) + + {:noreply, + socket + |> assign(:current_date, date) + |> stream(:records_on_this_day, records_on_this_day, reset: true)} + + {:error, _reason} -> + {:noreply, socket} + end + end + def handle_info(%{track_count: 0}, socket) do {:noreply, socket} end diff --git a/lib/music_library_web/live/stats_live/index.html.heex b/lib/music_library_web/live/stats_live/index.html.heex index 486ca6f1..4c01f53d 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -487,18 +487,27 @@ -
-
-

- {gettext("On This day")} -

+
+
+
+

+ {gettext("On This day")} +

+ <.form + :let={f} + for={to_form(%{"current_date" => @current_date})} + phx-change="set_current_date" + > + <.date_picker size="xs" field={f[:current_date]} /> + +
<.records_on_this_day current_date={@current_date} records={@streams.records_on_this_day} record_show_path={fn record -> ~p"/collection/#{record}" end} />
-
+

{gettext("Top %{n} Artists", %{n: length(@records_by_artist)})}

@@ -520,7 +529,7 @@
-
+

{gettext("Top %{n} Genres", %{n: length(@records_by_genre)})}