Resolve timezone from user browser
This commit is contained in:
@@ -27,5 +27,5 @@ defmodule MusicLibrary do
|
||||
- `MusicLibrary.Secrets` - Encrypted storage for API keys and sensitive configuration
|
||||
"""
|
||||
|
||||
def timezone, do: Application.fetch_env!(:music_library, :timezone)
|
||||
def default_timezone, do: Application.fetch_env!(:music_library, :default_timezone)
|
||||
end
|
||||
|
||||
@@ -214,7 +214,7 @@ defmodule MusicLibrary.ScrobbleActivity do
|
||||
def get_top_albums_by_days(days, opts) do
|
||||
limit = Keyword.get(opts, :limit, 10)
|
||||
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
||||
timezone = Keyword.get(opts, :timezone, &MusicLibrary.timezone/0)
|
||||
timezone = Keyword.get(opts, :timezone, &MusicLibrary.default_timezone/0)
|
||||
|
||||
cutoff_timestamp =
|
||||
current_time
|
||||
@@ -304,7 +304,7 @@ defmodule MusicLibrary.ScrobbleActivity do
|
||||
def get_top_artists_by_days(days, opts) do
|
||||
limit = Keyword.get(opts, :limit, 10)
|
||||
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
||||
timezone = Keyword.get(opts, :timezone, &MusicLibrary.timezone/0)
|
||||
timezone = Keyword.get(opts, :timezone, &MusicLibrary.default_timezone/0)
|
||||
|
||||
cutoff_timestamp =
|
||||
current_time
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule MusicLibraryWeb.Hooks.GetTimezone do
|
||||
use MusicLibraryWeb, :live_component
|
||||
|
||||
def on_mount(:default, _params, _session, socket) do
|
||||
connect_params = get_connect_params(socket)
|
||||
timezone = connect_params["timezone"] || MusicLibrary.default_timezone()
|
||||
|
||||
{:cont, assign(socket, :timezone, timezone)}
|
||||
end
|
||||
end
|
||||
@@ -25,7 +25,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:current_section, :collection)
|
||||
|> assign(:timezone, MusicLibrary.timezone())
|
||||
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|
||||
|> assign(:release_with_tracks, nil)}
|
||||
end
|
||||
|
||||
@@ -23,7 +23,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:timezone, MusicLibrary.timezone())
|
||||
|> stream_configure(:recent_tracks,
|
||||
dom_id: fn track -> "track-#{track.scrobbled_at_uts}" end
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ defmodule MusicLibraryWeb.Router do
|
||||
get "/artists/:musicbrainz_id/image", ArtistController, :image
|
||||
|
||||
live_session :default,
|
||||
on_mount: MusicLibraryWeb.Hooks.StaticAssets do
|
||||
on_mount: [MusicLibraryWeb.Hooks.StaticAssets, MusicLibraryWeb.Hooks.GetTimezone] do
|
||||
live "/", StatsLive.Index, :index
|
||||
|
||||
live "/collection", CollectionLive.Index, :index
|
||||
|
||||
Reference in New Issue
Block a user