Pick color extraction strategy from dropdown

This commit is contained in:
Claudio Ortolina
2025-06-08 20:01:49 +01:00
parent 2bbb91769d
commit 2cc1d7ca8f
10 changed files with 185 additions and 23 deletions
@@ -116,6 +116,26 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
end
end
def handle_event("extract_colors", %{"id" => id, "method" => method}, socket) do
record = Records.get_record!(id)
method = String.to_existing_atom(method)
case Records.extract_colors_async(record, method) do
{:ok, _worker} ->
{:noreply,
socket
|> put_flash(:info, gettext("In progress - record will update automatically"))}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error") <> "," <> inspect(reason)
)}
end
end
@impl true
def handle_info({MusicLibraryWeb.FormComponent, {:saved, record}}, socket) do
{:noreply, assign(socket, :record, record)}
@@ -91,6 +91,38 @@
{gettext("Populate genres")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700"
role="menuitem"
tabindex="0"
id={"actions-#{@record.id}-extract-colors-fast"}
phx-click={JS.push("extract_colors", value: %{id: @record.id, method: :fast})}
>
<.icon
name="hero-paint-brush"
class="h-4 w-4 mr-1 phx-click-loading:animate-shake"
aria-hidden="true"
data-slot="icon"
/>
{gettext("Extract colors (fast)")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700"
role="menuitem"
tabindex="0"
id={"actions-#{@record.id}-extract-colors-slow"}
phx-click={JS.push("extract_colors", value: %{id: @record.id, method: :slow})}
>
<.icon
name="hero-paint-brush"
class="h-4 w-4 mr-1 phx-click-loading:animate-shake"
aria-hidden="true"
data-slot="icon"
/>
{gettext("Extract colors (slow)")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-red-900 hover:bg-red-50 dark:text-red-700 dark:hover:bg-red-900/30 dark:hover:text-red-600"
role="menuitem"
@@ -117,6 +117,26 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
end
end
def handle_event("extract_colors", %{"id" => id, "method" => method}, socket) do
record = Records.get_record!(id)
method = String.to_existing_atom(method)
case Records.extract_colors_async(record, method) do
{:ok, _worker} ->
{:noreply,
socket
|> put_flash(:info, gettext("In progress - record will update automatically"))}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error") <> "," <> inspect(reason)
)}
end
end
@impl true
def handle_info({MusicLibraryWeb.FormComponent, {:saved, record}}, socket) do
{:noreply, assign(socket, :record, record)}
@@ -111,6 +111,38 @@
{gettext("Purchased")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700"
role="menuitem"
tabindex="0"
id={"actions-#{@record.id}-extract-colors-fast"}
phx-click={JS.push("extract_colors", value: %{id: @record.id, method: :fast})}
>
<.icon
name="hero-paint-brush"
class="h-4 w-4 mr-1 phx-click-loading:animate-shake"
aria-hidden="true"
data-slot="icon"
/>
{gettext("Extract colors (fast)")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700"
role="menuitem"
tabindex="0"
id={"actions-#{@record.id}-extract-colors-slow"}
phx-click={JS.push("extract_colors", value: %{id: @record.id, method: :slow})}
>
<.icon
name="hero-paint-brush"
class="h-4 w-4 mr-1 phx-click-loading:animate-shake"
aria-hidden="true"
data-slot="icon"
/>
{gettext("Extract colors (slow)")}
</.link>
<.link
class="block px-3 py-1 text-sm leading-6 text-red-900 hover:bg-red-50 dark:text-red-700 dark:hover:bg-red-900/30 dark:hover:text-red-600"
role="menuitem"