Extract StaticAssets hook with a single default live_session
This commit is contained in:
@@ -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
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
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)}
|
{:ok, assign(socket, :nav_section, :records)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(%{"id" => record_id}, _session, socket) do
|
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
|
if connected?(socket) do
|
||||||
Records.subscribe(record_id)
|
Records.subscribe(record_id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,13 +16,6 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
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()
|
current_date = DateTime.utc_now() |> DateTime.to_date()
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
|
|||||||
@@ -14,13 +14,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
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()
|
current_date = DateTime.utc_now() |> DateTime.to_date()
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
|
|||||||
@@ -39,25 +39,28 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/covers/:record_id", CoverController, :show
|
get "/covers/:record_id", CoverController, :show
|
||||||
get "/artists/:musicbrainz_id/image", ArtistController, :image
|
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", CollectionLive.Index, :index
|
||||||
live "/collection/import", CollectionLive.Index, :import
|
live "/collection/import", CollectionLive.Index, :import
|
||||||
live "/collection/scan", CollectionLive.Index, :barcode_scan
|
live "/collection/scan", CollectionLive.Index, :barcode_scan
|
||||||
live "/collection/:id/edit", CollectionLive.Index, :edit
|
live "/collection/:id/edit", CollectionLive.Index, :edit
|
||||||
|
|
||||||
live "/collection/:id", CollectionLive.Show, :show
|
live "/collection/:id", CollectionLive.Show, :show
|
||||||
live "/collection/:id/show/edit", CollectionLive.Show, :edit
|
live "/collection/:id/show/edit", CollectionLive.Show, :edit
|
||||||
|
|
||||||
live "/wishlist", WishlistLive.Index, :index
|
live "/wishlist", WishlistLive.Index, :index
|
||||||
live "/wishlist/import", WishlistLive.Index, :import
|
live "/wishlist/import", WishlistLive.Index, :import
|
||||||
live "/wishlist/:id/edit", WishlistLive.Index, :edit
|
live "/wishlist/:id/edit", WishlistLive.Index, :edit
|
||||||
|
|
||||||
live "/wishlist/:id", WishlistLive.Show, :show
|
live "/wishlist/:id", WishlistLive.Show, :show
|
||||||
live "/wishlist/:id/show/edit", WishlistLive.Show, :edit
|
live "/wishlist/:id/show/edit", WishlistLive.Show, :edit
|
||||||
|
|
||||||
live "/artists/:musicbrainz_id", ArtistLive.Show, :show
|
live "/artists/:musicbrainz_id", ArtistLive.Show, :show
|
||||||
live "/artists/:musicbrainz_id/import", ArtistLive.Show, :import
|
live "/artists/:musicbrainz_id/import", ArtistLive.Show, :import
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -203,10 +203,7 @@ msgstr ""
|
|||||||
msgid "Success!"
|
msgid "Success!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/collection_live/index.ex
|
#: lib/music_library_web/hooks/static_assets.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
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "The application has been updated, please reload."
|
msgid "The application has been updated, please reload."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|||||||
@@ -203,10 +203,7 @@ msgstr ""
|
|||||||
msgid "Success!"
|
msgid "Success!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/collection_live/index.ex
|
#: lib/music_library_web/hooks/static_assets.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
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "The application has been updated, please reload."
|
msgid "The application has been updated, please reload."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user