Add universal search support for record sets

This commit is contained in:
Claudio Ortolina
2026-02-06 20:47:00 +00:00
parent 68956978e1
commit ecd87ee2c6
4 changed files with 110 additions and 6 deletions
@@ -79,7 +79,8 @@ defmodule MusicLibraryWeb.UniversalSearchLive.Index do
total_results =
length(search_results.collection) +
length(search_results.wishlist) +
length(search_results.artists)
length(search_results.artists) +
length(search_results.record_sets)
{:noreply,
socket
@@ -145,11 +146,32 @@ defmodule MusicLibraryWeb.UniversalSearchLive.Index do
|> push_navigate(to: ~p"/wishlist?query=#{query}")}
end
@impl true
def handle_event("navigate_to_record_set", %{"id" => id}, socket) do
{:noreply,
socket
|> assign(:show_modal, false)
|> push_navigate(to: ~p"/record-sets/#{id}")}
end
@impl true
def handle_event("navigate_to_record_sets", %{"query" => query}, socket) do
{:noreply,
socket
|> assign(:show_modal, false)
|> push_navigate(to: ~p"/record-sets?query=#{query}")}
end
defp reset(socket) do
socket
|> assign(:search_query, "")
|> assign(:search_results, %{collection: [], wishlist: [], artists: []})
|> assign(:search_counts, %{collection_count: 0, wishlist_count: 0, artists_count: 0})
|> assign(:search_results, %{collection: [], wishlist: [], artists: [], record_sets: []})
|> assign(:search_counts, %{
collection_count: 0,
wishlist_count: 0,
artists_count: 0,
record_sets_count: 0
})
|> assign(:total_results, 0)
end
end
@@ -96,6 +96,30 @@
/>
</:actions>
</.search_result_group>
<.search_result_group
:if={length(@search_results.record_sets) > 0}
title="Record Sets"
count={length(@search_results.record_sets)}
total_count={@search_counts.record_sets_count}
>
<.search_result_record_set
:for={record_set <- @search_results.record_sets}
record_set={record_set}
phx-click="navigate_to_record_set"
phx-value-id={record_set.id}
phx-target={@myself}
/>
<:actions>
<.view_all_button
:if={@search_counts.record_sets_count > length(@search_results.record_sets)}
count={@search_counts.record_sets_count}
target="record set"
phx-click="navigate_to_record_sets"
phx-value-query={@search_query}
phx-target={@myself}
/>
</:actions>
</.search_result_group>
<.results_footer total_results={@total_results} />
</.structured_modal>
</div>