Open universal search modal instantly via client-side JS
Replace phx-click server event with Fluxon.open_dialog for zero-latency modal opening. The modal DOM is now always present (no :if conditional) so it can be shown instantly; the server syncs state in the background. Fix test selectors that now match the always-present modal form by scoping to forms without phx-target (which the modal form always has).
This commit is contained in:
@@ -11,7 +11,6 @@ defmodule MusicLibraryWeb.UniversalSearchLive.Index do
|
|||||||
~H"""
|
~H"""
|
||||||
<div id={@id} phx-hook="UniversalSearchNavigation">
|
<div id={@id} phx-hook="UniversalSearchNavigation">
|
||||||
<.structured_modal
|
<.structured_modal
|
||||||
:if={@show_modal}
|
|
||||||
id="universal-search-root"
|
id="universal-search-root"
|
||||||
open={@show_modal}
|
open={@show_modal}
|
||||||
on_close={JS.push("close_modal", value: %{}, target: "#universal-search")}
|
on_close={JS.push("close_modal", value: %{}, target: "#universal-search")}
|
||||||
@@ -184,8 +183,10 @@ defmodule MusicLibraryWeb.UniversalSearchLive.Index do
|
|||||||
id="universal-search-button"
|
id="universal-search-button"
|
||||||
variant="soft"
|
variant="soft"
|
||||||
title={gettext("Search (Cmd/Ctrl+K)")}
|
title={gettext("Search (Cmd/Ctrl+K)")}
|
||||||
phx-click="open_modal"
|
phx-click={
|
||||||
phx-target="#universal-search"
|
Fluxon.open_dialog("universal-search-root")
|
||||||
|
|> JS.push("open_modal", target: "#universal-search")
|
||||||
|
}
|
||||||
phx-hook=".SearchGlobalShortcut"
|
phx-hook=".SearchGlobalShortcut"
|
||||||
>
|
>
|
||||||
<span class="sr-only">{gettext("Search (Cmd/Ctrl+K)")}</span>
|
<span class="sr-only">{gettext("Search (Cmd/Ctrl+K)")}</span>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ defmodule MusicLibraryWeb.OnlineStoreTemplateLive.IndexTest do
|
|||||||
assert has_element?(view, "p", "Bandcamp")
|
assert has_element?(view, "p", "Bandcamp")
|
||||||
|
|
||||||
view
|
view
|
||||||
|> form("form", query: "Amazon")
|
|> form("form:not([phx-target])", query: "Amazon")
|
||||||
|> render_change()
|
|> render_change()
|
||||||
|
|
||||||
assert_patch(view, ~p"/online-store-templates?page=1&page_size=50&query=Amazon")
|
assert_patch(view, ~p"/online-store-templates?page=1&page_size=50&query=Amazon")
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
|
|||||||
test "renders search page with form", %{conn: conn} do
|
test "renders search page with form", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/scrobble")
|
|> visit(~p"/scrobble")
|
||||||
|> assert_has("form[phx-submit='search']")
|
|> assert_has("form[phx-submit='search']:not([phx-target])")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "shows connect Last.fm button when not authenticated", %{conn: conn} do
|
test "shows connect Last.fm button when not authenticated", %{conn: conn} do
|
||||||
@@ -67,7 +67,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
|
|||||||
session
|
session
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> form("form[phx-submit='search']", %{query: "marbles"})
|
|> form("form[phx-submit='search']:not([phx-target])", %{query: "marbles"})
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
|
|
||||||
render(view)
|
render(view)
|
||||||
@@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
|
|||||||
session
|
session
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> form("form[phx-submit='search']", %{query: ""})
|
|> form("form[phx-submit='search']:not([phx-target])", %{query: ""})
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
end)
|
end)
|
||||||
|> refute_has("h3", "Release Groups")
|
|> refute_has("h3", "Release Groups")
|
||||||
@@ -108,7 +108,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
|
|||||||
session
|
session
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> form("form[phx-submit='search']", %{query: "nonexistent"})
|
|> form("form[phx-submit='search']:not([phx-target])", %{query: "nonexistent"})
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
|
|
||||||
render(view)
|
render(view)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ defmodule MusicLibraryWeb.ScrobbleRulesLiveTest do
|
|||||||
{:ok, index_live, _html} = live(conn, ~p"/scrobble-rules")
|
{:ok, index_live, _html} = live(conn, ~p"/scrobble-rules")
|
||||||
|
|
||||||
index_live
|
index_live
|
||||||
|> form("form[phx-change='search']", query: scrobble_rule.match_value)
|
|> form("form[phx-change='search']:not([phx-target])", query: scrobble_rule.match_value)
|
||||||
|> render_change()
|
|> render_change()
|
||||||
|
|
||||||
assert_patch(index_live)
|
assert_patch(index_live)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|
|||||||
session
|
session
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> form("form[phx-submit='search']", %{query: "Unique Track"})
|
|> form("form[phx-submit='search']:not([phx-target])", %{query: "Unique Track"})
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
end)
|
end)
|
||||||
|> assert_has("p", "Unique Track Title")
|
|> assert_has("p", "Unique Track Title")
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|
|||||||
test "modal is hidden by default", %{conn: conn} do
|
test "modal is hidden by default", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection")
|
|> visit(~p"/collection")
|
||||||
|> refute_has("#universal-search-root")
|
|> assert_has("#universal-search-root[hidden]")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "modal opens when search button is clicked", %{conn: conn} do
|
test "modal opens when search button is clicked", %{conn: conn} do
|
||||||
|
|||||||
Reference in New Issue
Block a user