Streamline record detail actions, and add a quick scrobble everything button
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
defmodule MusicLibraryWeb.CollectionLive.Show do
|
defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||||
use MusicLibraryWeb, :live_view
|
use MusicLibraryWeb, :live_view
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
import MusicLibrary.ListeningStats, only: [localize_scrobbled_at: 2]
|
import MusicLibrary.ListeningStats, only: [localize_scrobbled_at: 2]
|
||||||
|
|
||||||
import MusicLibraryWeb.RecordComponents,
|
import MusicLibraryWeb.RecordComponents,
|
||||||
@@ -24,6 +26,8 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
alias MusicLibraryWeb.ErrorMessages
|
alias MusicLibraryWeb.ErrorMessages
|
||||||
alias Phoenix.LiveView.JS
|
alias Phoenix.LiveView.JS
|
||||||
|
|
||||||
|
alias MusicBrainz
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -44,12 +48,13 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
<div class="min-w-12">
|
<div class="min-w-12">
|
||||||
<.button_group>
|
<.button_group>
|
||||||
<.button
|
<.button
|
||||||
|
:if={@can_scrobble? and @record.selected_release_id}
|
||||||
variant="soft"
|
variant="soft"
|
||||||
phx-click={MusicLibraryWeb.Components.Notes.open("record-notes-sheet")}
|
phx-click="scrobble_release"
|
||||||
>
|
>
|
||||||
<span class="sr-only">{gettext("Open Notes")}</span>
|
<span class="sr-only">{gettext("Scrobble release")}</span>
|
||||||
<.icon
|
<.icon
|
||||||
name="hero-pencil"
|
name="hero-play"
|
||||||
class="h-5 w-5"
|
class="h-5 w-5"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
data-slot="icon"
|
data-slot="icon"
|
||||||
@@ -80,18 +85,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
data-slot="icon"
|
data-slot="icon"
|
||||||
/>
|
/>
|
||||||
</.button>
|
</.button>
|
||||||
<.button
|
|
||||||
variant="soft"
|
|
||||||
phx-click={Fluxon.open_dialog("debug-data")}
|
|
||||||
>
|
|
||||||
<span class="sr-only">{gettext("Debug data")}</span>
|
|
||||||
<.icon
|
|
||||||
name="hero-code-bracket"
|
|
||||||
class="h-5 w-5"
|
|
||||||
aria-hidden="true"
|
|
||||||
data-slot="icon"
|
|
||||||
/>
|
|
||||||
</.button>
|
|
||||||
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
|
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
|
||||||
<:toggle>
|
<:toggle>
|
||||||
<.button variant="soft">
|
<.button variant="soft">
|
||||||
@@ -105,6 +98,34 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
</.button>
|
</.button>
|
||||||
</:toggle>
|
</:toggle>
|
||||||
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
|
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
|
||||||
|
<.dropdown_link
|
||||||
|
id={"actions-#{@record.id}-notes"}
|
||||||
|
phx-click={MusicLibraryWeb.Components.Notes.open("record-notes-sheet")}
|
||||||
|
>
|
||||||
|
<.icon
|
||||||
|
name="hero-pencil"
|
||||||
|
class="h-4 w-4 mr-1"
|
||||||
|
aria-hidden="true"
|
||||||
|
data-slot="icon"
|
||||||
|
/>
|
||||||
|
{gettext("Notes")}
|
||||||
|
</.dropdown_link>
|
||||||
|
|
||||||
|
<.dropdown_link
|
||||||
|
id={"actions-#{@record.id}-debug"}
|
||||||
|
phx-click={Fluxon.open_dialog("debug-data")}
|
||||||
|
>
|
||||||
|
<.icon
|
||||||
|
name="hero-code-bracket"
|
||||||
|
class="h-4 w-4 mr-1"
|
||||||
|
aria-hidden="true"
|
||||||
|
data-slot="icon"
|
||||||
|
/>
|
||||||
|
{gettext("Debug data")}
|
||||||
|
</.dropdown_link>
|
||||||
|
|
||||||
|
<.dropdown_separator />
|
||||||
|
|
||||||
<.dropdown_link
|
<.dropdown_link
|
||||||
id={"actions-#{@record.id}-edit"}
|
id={"actions-#{@record.id}-edit"}
|
||||||
patch={~p"/collection/#{@record}/show/edit"}
|
patch={~p"/collection/#{@record}/show/edit"}
|
||||||
@@ -455,6 +476,46 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("scrobble_release", _params, socket) do
|
||||||
|
record = socket.assigns.record
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
start_async(socket, :scrobble_release, fn ->
|
||||||
|
with {:ok, release} <- MusicBrainz.get_release(record.selected_release_id) do
|
||||||
|
release_with_tracks = MusicBrainz.Release.from_api_response(release)
|
||||||
|
|
||||||
|
ScrobbleActivity.scrobble_release(release_with_tracks,
|
||||||
|
finished_at: DateTime.utc_now()
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end)}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_async(:scrobble_release, {:ok, {:ok, _result}}, socket) do
|
||||||
|
{:noreply, put_toast(socket, :info, gettext("Release scrobbled successfully"))}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_async(:scrobble_release, {:ok, {:error, reason}}, socket) do
|
||||||
|
{:noreply,
|
||||||
|
put_toast(
|
||||||
|
socket,
|
||||||
|
:error,
|
||||||
|
gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_async(:scrobble_release, {:exit, reason}, socket) do
|
||||||
|
Logger.error("Scrobble release failed: #{inspect(reason)}")
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
put_toast(
|
||||||
|
socket,
|
||||||
|
:error,
|
||||||
|
gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do
|
def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do
|
||||||
{:noreply,
|
{:noreply,
|
||||||
|
|||||||
@@ -52,18 +52,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
|
|||||||
data-slot="icon"
|
data-slot="icon"
|
||||||
/>
|
/>
|
||||||
</.button>
|
</.button>
|
||||||
<.button
|
|
||||||
variant="soft"
|
|
||||||
phx-click={Fluxon.open_dialog("debug-data")}
|
|
||||||
>
|
|
||||||
<span class="sr-only">{gettext("Debug data")}</span>
|
|
||||||
<.icon
|
|
||||||
name="hero-code-bracket"
|
|
||||||
class="h-5 w-5"
|
|
||||||
aria-hidden="true"
|
|
||||||
data-slot="icon"
|
|
||||||
/>
|
|
||||||
</.button>
|
|
||||||
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
|
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
|
||||||
<:toggle>
|
<:toggle>
|
||||||
<.button variant="soft">
|
<.button variant="soft">
|
||||||
@@ -77,6 +65,21 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
|
|||||||
</.button>
|
</.button>
|
||||||
</:toggle>
|
</:toggle>
|
||||||
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
|
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
|
||||||
|
<.dropdown_link
|
||||||
|
id={"actions-#{@record.id}-debug"}
|
||||||
|
phx-click={Fluxon.open_dialog("debug-data")}
|
||||||
|
>
|
||||||
|
<.icon
|
||||||
|
name="hero-code-bracket"
|
||||||
|
class="h-4 w-4 mr-1"
|
||||||
|
aria-hidden="true"
|
||||||
|
data-slot="icon"
|
||||||
|
/>
|
||||||
|
{gettext("Debug data")}
|
||||||
|
</.dropdown_link>
|
||||||
|
|
||||||
|
<.dropdown_separator />
|
||||||
|
|
||||||
<.dropdown_link
|
<.dropdown_link
|
||||||
id={"actions-#{@record.id}-edit"}
|
id={"actions-#{@record.id}-edit"}
|
||||||
patch={~p"/wishlist/#{@record}/show/edit"}
|
patch={~p"/wishlist/#{@record}/show/edit"}
|
||||||
|
|||||||
@@ -674,12 +674,14 @@ msgid "Successfully connected your Last.fm account"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#: lib/music_library_web/live/scrobble_live/show.ex
|
#: lib/music_library_web/live/scrobble_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Error scrobbling release"
|
msgid "Error scrobbling release"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#: lib/music_library_web/live/scrobble_live/show.ex
|
#: lib/music_library_web/live/scrobble_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Release scrobbled successfully"
|
msgid "Release scrobbled successfully"
|
||||||
@@ -697,6 +699,7 @@ msgid "Scrobbling..."
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Scrobble release"
|
msgid "Scrobble release"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -1295,7 +1298,6 @@ msgid "Note updated successfully"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/show.ex
|
#: lib/music_library_web/live/artist_live/show.ex
|
||||||
#: lib/music_library_web/live/collection_live/show.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Open Notes"
|
msgid "Open Notes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -2277,3 +2279,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Sending..."
|
msgid "Sending..."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Notes"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -674,12 +674,14 @@ msgid "Successfully connected your Last.fm account"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#: lib/music_library_web/live/scrobble_live/show.ex
|
#: lib/music_library_web/live/scrobble_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Error scrobbling release"
|
msgid "Error scrobbling release"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#: lib/music_library_web/live/scrobble_live/show.ex
|
#: lib/music_library_web/live/scrobble_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Release scrobbled successfully"
|
msgid "Release scrobbled successfully"
|
||||||
@@ -697,6 +699,7 @@ msgid "Scrobbling..."
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/release.ex
|
#: lib/music_library_web/components/release.ex
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Scrobble release"
|
msgid "Scrobble release"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -1295,7 +1298,6 @@ msgid "Note updated successfully"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/show.ex
|
#: lib/music_library_web/live/artist_live/show.ex
|
||||||
#: lib/music_library_web/live/collection_live/show.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Open Notes"
|
msgid "Open Notes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -2277,3 +2279,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Sending..."
|
msgid "Sending..."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Notes"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user