From a509248625e080fc15158d6ef5ba31c60efbd74c Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 13 Apr 2026 10:12:49 +0100 Subject: [PATCH] Wire up Chat component in CollectionLive.Index --- .../live/collection_live/index.ex | 37 ++++++++++++++++++- priv/gettext/default.pot | 15 ++++++++ .../live/collection_live/index_test.exs | 6 +++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/music_library_web/live/collection_live/index.ex b/lib/music_library_web/live/collection_live/index.ex index 0423bd9c..33b18b5e 100644 --- a/lib/music_library_web/live/collection_live/index.ex +++ b/lib/music_library_web/live/collection_live/index.ex @@ -6,6 +6,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do import MusicLibraryWeb.LiveHelpers.Params import MusicLibraryWeb.RecordComponents + alias MusicLibrary.Chats alias MusicLibrary.Collection alias MusicLibrary.Records @@ -47,6 +48,20 @@ defmodule MusicLibraryWeb.CollectionLive.Index do <.barcode_icon class="icon fill-current" /> {gettext("Scan")} + <.button + variant="solid" + size="sm" + phx-click={MusicLibraryWeb.Components.Chat.open("collection-chat-sheet")} + > + <.icon + name="hero-chat-bubble-left-right" + class="icon" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Chat")} + 0} class="text-xs font-medium">{@chat_count} + @@ -189,6 +204,19 @@ defmodule MusicLibraryWeb.CollectionLive.Index do <.pagination id={:bottom_pagination} pagination_params={@record_list_params} /> + + <.live_component + id="collection-chat" + sheet_id="collection-chat-sheet" + module={MusicLibraryWeb.Components.Chat} + title={gettext("Collection")} + entity={:collection} + musicbrainz_id={Chats.collection_musicbrainz_id()} + chat_module={MusicLibrary.Chats.CollectionChat} + chat_context={@collection_summary} + placeholder={gettext("Ask about your collection...")} + empty_prompt={gettext("Ask anything about your music collection")} + /> """ end @@ -199,7 +227,9 @@ defmodule MusicLibraryWeb.CollectionLive.Index do socket |> assign(:current_section, :collection) |> assign(:import_query, "") - |> assign(:display, :grid)} + |> assign(:display, :grid) + |> assign(:collection_summary, Collection.collection_summary()) + |> assign(:chat_count, Chats.count_chats(:collection, Chats.collection_musicbrainz_id()))} end @impl true @@ -252,6 +282,11 @@ defmodule MusicLibraryWeb.CollectionLive.Index do {:noreply, load_and_assign_records(socket, socket.assigns.record_list_params)} end + def handle_info({MusicLibraryWeb.Components.Chat, :chats_changed}, socket) do + chat_count = Chats.count_chats(:collection, Chats.collection_musicbrainz_id()) + {:noreply, assign(socket, :chat_count, chat_count)} + end + @impl true def handle_event("delete", %{"id" => id}, socket) do record = Records.get_record!(id) diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 39cdd6e3..00e03026 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -2407,3 +2407,18 @@ msgstr[1] "" #, elixir-autogen, elixir-format msgid "Copy message" msgstr "" + +#: lib/music_library_web/live/collection_live/index.ex +#, elixir-autogen, elixir-format +msgid "Ask about your collection..." +msgstr "" + +#: lib/music_library_web/live/collection_live/index.ex +#, elixir-autogen, elixir-format +msgid "Ask anything about your music collection" +msgstr "" + +#: lib/music_library_web/live/collection_live/index.ex +#, elixir-autogen, elixir-format +msgid "Chat" +msgstr "" diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs index 512f495e..8f9065b3 100644 --- a/test/music_library_web/live/collection_live/index_test.exs +++ b/test/music_library_web/live/collection_live/index_test.exs @@ -23,6 +23,12 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do describe "Collection" do setup [:fill_collection] + test "shows the chat button", %{conn: conn} do + conn + |> visit(~p"/collection") + |> assert_has("button", "Chat") + end + test "does not show wishlist records", %{conn: conn} do wishlist_records = Enum.map(1..3, fn _ -> record(%{purchased_at: nil}) end) session = visit(conn, ~p"/collection")