Rename /search to /import
This commit is contained in:
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
defmodule MusicLibraryWeb.RecordLive.SearchComponent do
|
defmodule MusicLibraryWeb.RecordLive.ImportComponent do
|
||||||
use MusicLibraryWeb, :live_component
|
use MusicLibraryWeb, :live_component
|
||||||
|
|
||||||
alias MusicLibrary.Records
|
alias MusicLibrary.Records
|
||||||
@@ -17,13 +17,13 @@ defmodule MusicLibraryWeb.RecordLive.SearchComponent do
|
|||||||
<.input
|
<.input
|
||||||
field={@form[:query]}
|
field={@form[:query]}
|
||||||
type="text"
|
type="text"
|
||||||
label="Search"
|
label="Search for a record on MusicBrainz"
|
||||||
prompt="Search for records"
|
prompt="Search for records"
|
||||||
phx-debounce="500"
|
phx-debounce="500"
|
||||||
/>
|
/>
|
||||||
</.simple_form>
|
</.simple_form>
|
||||||
<ul role="list" class="divide-y divide-gray-100">
|
<ul role="list" class="divide-y divide-gray-100">
|
||||||
<.result :for={record <- @records} record={record} />
|
<.result :for={release_group <- @release_groups} release_group={release_group} />
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
@@ -33,22 +33,22 @@ defmodule MusicLibraryWeb.RecordLive.SearchComponent do
|
|||||||
~H"""
|
~H"""
|
||||||
<li
|
<li
|
||||||
class="flex justify-between gap-x-6 py-5 cursor-pointer hover:bg-gray-50"
|
class="flex justify-between gap-x-6 py-5 cursor-pointer hover:bg-gray-50"
|
||||||
phx-click={JS.push("import", value: %{id: @record.id}, page_loading: true)}
|
phx-click={JS.push("import", value: %{id: @release_group.id}, page_loading: true)}
|
||||||
>
|
>
|
||||||
<div class="flex min-w-0 gap-x-4">
|
<div class="flex min-w-0 gap-x-4">
|
||||||
<div class="min-w-0 flex-auto">
|
<div class="min-w-0 flex-auto">
|
||||||
<p class="text-sm font-semibold leading-6 text-gray-900">
|
<p class="text-sm font-semibold leading-6 text-gray-900">
|
||||||
<%= @record.title %>
|
<%= @release_group.title %>
|
||||||
|
|
||||||
<span class="mt-1 text-xs leading-5 text-gray-500">
|
<span class="mt-1 text-xs leading-5 text-gray-500">
|
||||||
<%= @record.year %>
|
<%= @release_group.year %>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500"><%= @record.artists %></p>
|
<p class="mt-1 truncate text-xs leading-5 text-gray-500"><%= @release_group.artists %></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden shrink-0 sm:flex sm:flex-col sm:items-end">
|
<div class="hidden shrink-0 sm:flex sm:flex-col sm:items-end">
|
||||||
<.type_badge type={@record.type} />
|
<.type_badge type={@release_group.type} />
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
"""
|
"""
|
||||||
@@ -68,17 +68,17 @@ defmodule MusicLibraryWeb.RecordLive.SearchComponent do
|
|||||||
def mount(socket) do
|
def mount(socket) do
|
||||||
{:ok,
|
{:ok,
|
||||||
socket
|
socket
|
||||||
|> assign(:records, [])
|
|> assign(:release_groups, [])
|
||||||
|> assign(:form, to_form(%{"query" => ""}))}
|
|> assign(:form, to_form(%{"query" => ""}))}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("search", %{"query" => query}, socket) do
|
def handle_event("search", %{"query" => query}, socket) do
|
||||||
{:ok, records} = search(query)
|
{:ok, release_groups} = search(query)
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:records, records)
|
|> assign(:release_groups, release_groups)
|
||||||
|> assign(:form, to_form(%{"query" => query}))}
|
|> assign(:form, to_form(%{"query" => query}))}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,9 +23,9 @@ defmodule MusicLibraryWeb.RecordLive.Index do
|
|||||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(socket, :search, _params) do
|
defp apply_action(socket, :import, _params) do
|
||||||
socket
|
socket
|
||||||
|> assign(:page_title, "Search Records")
|
|> assign(:page_title, "Import from MusicBrainz")
|
||||||
|> assign(:record, nil)
|
|> assign(:record, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<.header>
|
<.header>
|
||||||
Listing Records
|
Listing Records
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link patch={~p"/records/search"}>
|
<.link patch={~p"/records/import"}>
|
||||||
<.button>Search Record</.button>
|
<.button>Import from MusicBrainz</.button>
|
||||||
</.link>
|
</.link>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
@@ -50,9 +50,9 @@
|
|||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
<.modal :if={@live_action == :search} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
|
<.modal :if={@live_action == :import} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
|
||||||
<.live_component
|
<.live_component
|
||||||
module={MusicLibraryWeb.RecordLive.SearchComponent}
|
module={MusicLibraryWeb.RecordLive.ImportComponent}
|
||||||
id={:search}
|
id={:search}
|
||||||
title={@page_title}
|
title={@page_title}
|
||||||
action={@live_action}
|
action={@live_action}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/images/:record_id", ImageController, :show
|
get "/images/:record_id", ImageController, :show
|
||||||
|
|
||||||
live "/records", RecordLive.Index, :index
|
live "/records", RecordLive.Index, :index
|
||||||
live "/records/search", RecordLive.Index, :search
|
live "/records/import", RecordLive.Index, :import
|
||||||
live "/records/:id/edit", RecordLive.Index, :edit
|
live "/records/:id/edit", RecordLive.Index, :edit
|
||||||
|
|
||||||
live "/records/:id", RecordLive.Show, :show
|
live "/records/:id", RecordLive.Show, :show
|
||||||
|
|||||||
Reference in New Issue
Block a user