diff --git a/lib/music_library_web/components/stats_components.ex b/lib/music_library_web/components/stats_components.ex index 2a770c0e..ff0e4cbe 100644 --- a/lib/music_library_web/components/stats_components.ex +++ b/lib/music_library_web/components/stats_components.ex @@ -337,4 +337,23 @@ defmodule MusicLibraryWeb.StatsComponents do _other -> "" end end + + attr :container_class, :string, default: nil + slot :title, required: true + slot :side_actions + slot :inner_block, required: true + + def section(assigns) do + ~H""" +
+
+

+ {render_slot(@title)} +

+ {render_slot(@side_actions)} +
+ {render_slot(@inner_block)} +
+ """ + end end diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index 5ece9bbe..a55e7b82 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -227,191 +227,191 @@ defmodule MusicLibraryWeb.StatsLive.Index do ~H"""
<.tabs id="scrobble-activity" class="mt-4"> -
-
-

- {gettext("Scrobble activity")} -

+ <.section> + <:title> + {gettext("Scrobble activity")} <.refresh_lastfm_feed_button /> -
- <.tabs_list active_tab={@scrobble_activity_mode} variant="segmented"> - <:tab - name="albums" - phx-click={JS.push("set_scrobble_activity_mode", value: %{mode: "albums"})} + + <:side_actions> + <.tabs_list active_tab={@scrobble_activity_mode} variant="segmented"> + <:tab + name="albums" + phx-click={JS.push("set_scrobble_activity_mode", value: %{mode: "albums"})} + > + {gettext("Albums")} + + <:tab + name="tracks" + phx-click={JS.push("set_scrobble_activity_mode", value: %{mode: "tracks"})} + > + {gettext("Tracks")} + + + + <.tabs_panel name="albums" active={@scrobble_activity_mode == "albums"}> +
- <.tabs_panel name="albums" active={@scrobble_activity_mode == "albums"}> -
- - - - <.tabs_panel name="tracks" active={@scrobble_activity_mode == "tracks"}> - - + + + + <.tabs_panel name="tracks" active={@scrobble_activity_mode == "tracks"}> + + + """ @@ -516,25 +516,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do """ end - attr :container_class, :string, default: nil - slot :title, required: true - slot :side_actions - slot :inner_block, required: true - - defp section(assigns) do - ~H""" -
-
-

- {render_slot(@title)} -

- {render_slot(@side_actions)} -
- {render_slot(@inner_block)} -
- """ - end - defp assign_counts(socket) do collection_count_by_format = Collection.count_records_by_format() diff --git a/lib/music_library_web/live/stats_live/top_by_period.ex b/lib/music_library_web/live/stats_live/top_by_period.ex index 909dbf45..3ca27081 100644 --- a/lib/music_library_web/live/stats_live/top_by_period.ex +++ b/lib/music_library_web/live/stats_live/top_by_period.ex @@ -1,6 +1,8 @@ defmodule MusicLibraryWeb.StatsLive.TopByPeriod do use MusicLibraryWeb, :live_component + import MusicLibraryWeb.StatsComponents, only: [section: 1] + attr :id, :string, required: true attr :title, :string, required: true attr :key, :atom, required: true @@ -19,67 +21,67 @@ defmodule MusicLibraryWeb.StatsLive.TopByPeriod do @impl true def render(assigns) do ~H""" -
+
<.tabs> -
-

- {@title} -

- <.tabs_list active_tab={name_from_period(@key, @period)} variant="segmented" size="xs"> - <:tab - class="flex-1" - name={"#{@key}_last_7_days"} - phx-click={JS.push("set_period", value: %{period: "last_7_days"})} - phx-target={@myself} - > - {gettext("7d")} - - <:tab - class="flex-1" - name={"#{@key}_last_30_days"} - phx-click={JS.push("set_period", value: %{period: "last_30_days"})} - phx-target={@myself} - > - {gettext("30d")} - - <:tab - class="flex-1" - name={"#{@key}_last_90_days"} - phx-click={JS.push("set_period", value: %{period: "last_90_days"})} - phx-target={@myself} - > - {gettext("90d")} - - <:tab - class="flex-1" - name={"#{@key}_last_365_days"} - phx-click={JS.push("set_period", value: %{period: "last_365_days"})} - phx-target={@myself} - > - {gettext("1y")} - - <:tab - class="flex-1" - name={"#{@key}_all_time"} - phx-click={JS.push("set_period", value: %{period: "all_time"})} - phx-target={@myself} - > - {gettext("∞")} - - -
- <.async_result :let={items} assign={assigns[@key]}> - <:loading> -
- <.loading /> + <.section> + <:title>{@title} + <:side_actions> + <.tabs_list active_tab={name_from_period(@key, @period)} variant="segmented" size="xs"> + <:tab + class="flex-1" + name={"#{@key}_last_7_days"} + phx-click={JS.push("set_period", value: %{period: "last_7_days"})} + phx-target={@myself} + > + {gettext("7d")} + + <:tab + class="flex-1" + name={"#{@key}_last_30_days"} + phx-click={JS.push("set_period", value: %{period: "last_30_days"})} + phx-target={@myself} + > + {gettext("30d")} + + <:tab + class="flex-1" + name={"#{@key}_last_90_days"} + phx-click={JS.push("set_period", value: %{period: "last_90_days"})} + phx-target={@myself} + > + {gettext("90d")} + + <:tab + class="flex-1" + name={"#{@key}_last_365_days"} + phx-click={JS.push("set_period", value: %{period: "last_365_days"})} + phx-target={@myself} + > + {gettext("1y")} + + <:tab + class="flex-1" + name={"#{@key}_all_time"} + phx-click={JS.push("set_period", value: %{period: "all_time"})} + phx-target={@myself} + > + {gettext("∞")} + + + + <.async_result :let={items} assign={assigns[@key]}> + <:loading> +
+ <.loading /> +
+ +
+
+ {render_slot(@item, items)} +
- -
-
- {render_slot(@item, items)} -
-
- + +
"""