Extract StaticAssets hook with a single default live_session

This commit is contained in:
Claudio Ortolina
2025-05-13 21:03:59 +01:00
parent bb6fffca38
commit bb4fce61c7
8 changed files with 33 additions and 50 deletions
@@ -0,0 +1,14 @@
defmodule MusicLibraryWeb.Hooks.StaticAssets do
use MusicLibraryWeb, :live_component
def on_mount(:default, _params, _session, socket) do
socket =
if static_changed?(socket) do
put_flash(socket, :warning, gettext("The application has been updated, please reload."))
else
socket
end
{:cont, socket}
end
end
@@ -17,13 +17,6 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
@impl true
def mount(_params, _session, socket) do
socket =
if static_changed?(socket) do
put_flash(socket, :warning, gettext("The application has been updated, please reload."))
else
socket
end
{:ok, assign(socket, :nav_section, :records)}
end
@@ -15,13 +15,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
@impl true
def mount(%{"id" => record_id}, _session, socket) do
socket =
if static_changed?(socket) do
put_flash(socket, :warning, gettext("The application has been updated, please reload."))
else
socket
end
if connected?(socket) do
Records.subscribe(record_id)
end
@@ -16,13 +16,6 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
@impl true
def mount(_params, _session, socket) do
socket =
if static_changed?(socket) do
put_flash(socket, :warning, gettext("The application has been updated, please reload."))
else
socket
end
current_date = DateTime.utc_now() |> DateTime.to_date()
{:ok,
@@ -14,13 +14,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
@impl true
def mount(_params, _session, socket) do
socket =
if static_changed?(socket) do
put_flash(socket, :warning, gettext("The application has been updated, please reload."))
else
socket
end
current_date = DateTime.utc_now() |> DateTime.to_date()
{:ok,
+17 -14
View File
@@ -39,25 +39,28 @@ defmodule MusicLibraryWeb.Router do
get "/covers/:record_id", CoverController, :show
get "/artists/:musicbrainz_id/image", ArtistController, :image
live "/", StatsLive.Index, :index
live_session :default,
on_mount: MusicLibraryWeb.Hooks.StaticAssets do
live "/", StatsLive.Index, :index
live "/collection", CollectionLive.Index, :index
live "/collection/import", CollectionLive.Index, :import
live "/collection/scan", CollectionLive.Index, :barcode_scan
live "/collection/:id/edit", CollectionLive.Index, :edit
live "/collection", CollectionLive.Index, :index
live "/collection/import", CollectionLive.Index, :import
live "/collection/scan", CollectionLive.Index, :barcode_scan
live "/collection/:id/edit", CollectionLive.Index, :edit
live "/collection/:id", CollectionLive.Show, :show
live "/collection/:id/show/edit", CollectionLive.Show, :edit
live "/collection/:id", CollectionLive.Show, :show
live "/collection/:id/show/edit", CollectionLive.Show, :edit
live "/wishlist", WishlistLive.Index, :index
live "/wishlist/import", WishlistLive.Index, :import
live "/wishlist/:id/edit", WishlistLive.Index, :edit
live "/wishlist", WishlistLive.Index, :index
live "/wishlist/import", WishlistLive.Index, :import
live "/wishlist/:id/edit", WishlistLive.Index, :edit
live "/wishlist/:id", WishlistLive.Show, :show
live "/wishlist/:id/show/edit", WishlistLive.Show, :edit
live "/wishlist/:id", WishlistLive.Show, :show
live "/wishlist/:id/show/edit", WishlistLive.Show, :edit
live "/artists/:musicbrainz_id", ArtistLive.Show, :show
live "/artists/:musicbrainz_id/import", ArtistLive.Show, :import
live "/artists/:musicbrainz_id", ArtistLive.Show, :show
live "/artists/:musicbrainz_id/import", ArtistLive.Show, :import
end
end
end
+1 -4
View File
@@ -203,10 +203,7 @@ msgstr ""
msgid "Success!"
msgstr ""
#: lib/music_library_web/live/collection_live/index.ex
#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/index.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#: lib/music_library_web/hooks/static_assets.ex
#, elixir-autogen, elixir-format
msgid "The application has been updated, please reload."
msgstr ""
+1 -4
View File
@@ -203,10 +203,7 @@ msgstr ""
msgid "Success!"
msgstr ""
#: lib/music_library_web/live/collection_live/index.ex
#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/index.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#: lib/music_library_web/hooks/static_assets.ex
#, elixir-autogen, elixir-format
msgid "The application has been updated, please reload."
msgstr ""