Make timezone configurable

This commit is contained in:
Claudio Ortolina
2025-04-10 18:34:05 +01:00
parent 9cae628d4e
commit 32c11f86c9
4 changed files with 16 additions and 4 deletions
@@ -10,8 +10,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
attr :title, :string, required: true
attr :class, :string
@timezone "Europe/London"
defp album_preview(assigns) do
~H"""
<div
@@ -85,6 +83,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
{:ok,
socket
|> assign(:timezone, resolve_timezone!())
|> stream_configure(:recent_tracks,
dom_id: fn track -> "track-#{track.scrobbled_at_uts}" end
)
@@ -173,7 +172,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
Enum.map(recent_tracks, fn t ->
%{
t
| scrobbled_at_label: localize_scrobbled_at(t.scrobbled_at_uts, @timezone)
| scrobbled_at_label: localize_scrobbled_at(t.scrobbled_at_uts, socket.assigns.timezone)
}
end)
@@ -272,4 +271,9 @@ defmodule MusicLibraryWeb.StatsLive.Index do
JS.hide(to: "#actions-#{track_id}")
|> JS.remove_class("pointer-events-none", to: "#scrobble-activity > li")
end
defp resolve_timezone! do
Application.get_env(:music_library, MusicLibraryWeb)
|> Keyword.fetch!(:timezone)
end
end