Count formats in results
This commit is contained in:
@@ -67,7 +67,7 @@ defmodule MusicLibraryWeb.Components.AddRecord do
|
|||||||
id={"musicbrainz_#{release_group.id}"}
|
id={"musicbrainz_#{release_group.id}"}
|
||||||
myself={@myself}
|
myself={@myself}
|
||||||
in_cart?={in_cart?(@cart_pairs, release_group.id)}
|
in_cart?={in_cart?(@cart_pairs, release_group.id)}
|
||||||
cart_format={cart_format(@cart, release_group.id)}
|
cart_formats={cart_formats(@cart, release_group.id)}
|
||||||
release_group={release_group}
|
release_group={release_group}
|
||||||
icon_name={@icon_name}
|
icon_name={@icon_name}
|
||||||
/>
|
/>
|
||||||
@@ -241,14 +241,17 @@ defmodule MusicLibraryWeb.Components.AddRecord do
|
|||||||
attr :release_group, MusicBrainz.ReleaseGroupSearchResult, required: true
|
attr :release_group, MusicBrainz.ReleaseGroupSearchResult, required: true
|
||||||
attr :myself, :any, required: true
|
attr :myself, :any, required: true
|
||||||
attr :in_cart?, :boolean, required: true
|
attr :in_cart?, :boolean, required: true
|
||||||
attr :cart_format, :atom, required: true
|
attr :cart_formats, :list, required: true
|
||||||
|
|
||||||
defp result(assigns) do
|
defp result(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<li id={@id} class="flex justify-between gap-x-6 py-5 hover:bg-zinc-100 dark:hover:bg-zinc-700">
|
<li
|
||||||
<div class="flex w-full shrink-0 items-center justify-between px-4">
|
id={@id}
|
||||||
|
class="flex justify-between gap-x-6 py-5 md:px-4 hover:bg-zinc-100 dark:hover:bg-zinc-700"
|
||||||
|
>
|
||||||
|
<div class="flex w-full shrink-0 items-center justify-between">
|
||||||
<img
|
<img
|
||||||
class="mr-4 w-20 flex-none rounded-lg"
|
class="mr-4 w-12 md:w-20 flex-none rounded-lg"
|
||||||
alt={@release_group.title}
|
alt={@release_group.title}
|
||||||
src={ReleaseGroupSearchResult.thumb_url(@release_group)}
|
src={ReleaseGroupSearchResult.thumb_url(@release_group)}
|
||||||
onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"}
|
onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"}
|
||||||
@@ -272,7 +275,8 @@ defmodule MusicLibraryWeb.Components.AddRecord do
|
|||||||
class="mr-2 inline-flex items-center gap-1 rounded-full bg-emerald-100 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 text-xs font-medium px-2 py-0.5"
|
class="mr-2 inline-flex items-center gap-1 rounded-full bg-emerald-100 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 text-xs font-medium px-2 py-0.5"
|
||||||
>
|
>
|
||||||
<.icon name="hero-check" class="size-3" aria-hidden="true" data-slot="icon" />
|
<.icon name="hero-check" class="size-3" aria-hidden="true" data-slot="icon" />
|
||||||
{gettext("In cart · %{format}", format: format_label(@cart_format))}
|
<span :if={length(@cart_formats) > 1}>{length(@cart_formats)}</span>
|
||||||
|
<span class="sr-only sm:not-sr-only">{gettext("In cart")}</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<.dropdown id={"actions-#{@release_group.id}"} placement="bottom-end">
|
<.dropdown id={"actions-#{@release_group.id}"} placement="bottom-end">
|
||||||
@@ -615,11 +619,10 @@ defmodule MusicLibraryWeb.Components.AddRecord do
|
|||||||
Enum.any?(cart_pairs, fn {id, _format} -> id == rg_id end)
|
Enum.any?(cart_pairs, fn {id, _format} -> id == rg_id end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp cart_format(cart, rg_id) do
|
defp cart_formats(cart, rg_id) do
|
||||||
case Enum.find(cart, &(&1.release_group_id == rg_id)) do
|
cart
|
||||||
nil -> nil
|
|> Enum.filter(&(&1.release_group_id == rg_id))
|
||||||
item -> item.format
|
|> Enum.map(& &1.format)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||||
|
|||||||
@@ -2497,11 +2497,6 @@ msgid_plural "Import %{count} records"
|
|||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/add_record.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
|
||||||
msgid "In cart · %{format}"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: lib/music_library_web/components/add_record.ex
|
#: lib/music_library_web/components/add_record.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Toggle cart"
|
msgid "Toggle cart"
|
||||||
@@ -2516,3 +2511,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Error queuing records for import"
|
msgid "Error queuing records for import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/add_record.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "In cart"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -2497,11 +2497,6 @@ msgid_plural "Import %{count} records"
|
|||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/add_record.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
|
||||||
msgid "In cart · %{format}"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: lib/music_library_web/components/add_record.ex
|
#: lib/music_library_web/components/add_record.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Toggle cart"
|
msgid "Toggle cart"
|
||||||
@@ -2516,3 +2511,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Error queuing records for import"
|
msgid "Error queuing records for import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/add_record.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "In cart"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -293,8 +293,10 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> visit(~p"/collection/import")
|
|> visit(~p"/collection/import")
|
||||||
|> fill_in("Search for a record", with: "Marillion Marbles")
|
|> fill_in("Search for a record", with: "Marillion Marbles")
|
||||||
|> click_link("#musicbrainz_#{first_id} a", "CD")
|
|> click_link("#musicbrainz_#{first_id} a", "CD")
|
||||||
|> assert_has("#musicbrainz_#{first_id} span", text: "In cart · CD")
|
|> assert_has("#musicbrainz_#{first_id} span", text: "In cart")
|
||||||
|> assert_has("#cart-items li", count: 1)
|
|> assert_has("#cart-items li", count: 1)
|
||||||
|
|> click_link("#musicbrainz_#{first_id} a", "Vinyl")
|
||||||
|
|> assert_has("#musicbrainz_#{first_id} span", text: "2 In cart")
|
||||||
|
|
||||||
assert MusicLibrary.Repo.all(Record) == []
|
assert MusicLibrary.Repo.all(Record) == []
|
||||||
refute_enqueued(worker: ImportFromMusicbrainzReleaseGroup)
|
refute_enqueued(worker: ImportFromMusicbrainzReleaseGroup)
|
||||||
@@ -370,7 +372,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> LVT.element("#cart-items form")
|
|> LVT.element("#cart-items form")
|
||||||
|> LVT.render_change(%{"format" => "vinyl"})
|
|> LVT.render_change(%{"format" => "vinyl"})
|
||||||
|
|
||||||
assert LVT.render(view) =~ "In cart · Vinyl"
|
assert LVT.render(view) =~ "In cart"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejects change_format when the resulting pair is already in the cart", %{conn: conn} do
|
test "rejects change_format when the resulting pair is already in the cart", %{conn: conn} do
|
||||||
|
|||||||
Reference in New Issue
Block a user