Enable Ctrl/Meta+K to trigger universal search
This commit is contained in:
@@ -23,11 +23,13 @@ import { LiveSocket } from "phoenix_live_view";
|
|||||||
import topbar from "../vendor/topbar";
|
import topbar from "../vendor/topbar";
|
||||||
import { Hooks as FluxonHooks, DOM as FluxonDOM } from "fluxon";
|
import { Hooks as FluxonHooks, DOM as FluxonDOM } from "fluxon";
|
||||||
import BarcodeScannerHook from "./barcode-scanner";
|
import BarcodeScannerHook from "./barcode-scanner";
|
||||||
|
import SearchGlobalShortcut from "./search-global-shortcut";
|
||||||
import confetti from "canvas-confetti";
|
import confetti from "canvas-confetti";
|
||||||
import { createLiveToastHook } from "live_toast";
|
import { createLiveToastHook } from "live_toast";
|
||||||
|
|
||||||
let Hooks = FluxonHooks;
|
let Hooks = FluxonHooks;
|
||||||
Hooks.BarcodeScanner = BarcodeScannerHook;
|
Hooks.BarcodeScanner = BarcodeScannerHook;
|
||||||
|
Hooks.SearchGlobalShortcut = SearchGlobalShortcut;
|
||||||
Hooks.LiveToast = createLiveToastHook();
|
Hooks.LiveToast = createLiveToastHook();
|
||||||
|
|
||||||
let csrfToken = document
|
let csrfToken = document
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export default {
|
||||||
|
mounted() {
|
||||||
|
const universalSearchButton = document.querySelector("#universal-search-button");
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
switch (event.key) {
|
||||||
|
case "k":
|
||||||
|
if (event.metaKey || event.ctrlKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
universalSearchButton.click();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -39,10 +39,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex space-x-2 md:space-x-4 items-center">
|
<div class="flex space-x-2 md:space-x-4 items-center">
|
||||||
<.button
|
<.button
|
||||||
|
id="universal-search-button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
title={gettext("Search (Ctrl+K)")}
|
title={gettext("Search (Ctrl+K)")}
|
||||||
phx-click="open_modal"
|
phx-click="open_modal"
|
||||||
phx-target="#universal-search"
|
phx-target="#universal-search"
|
||||||
|
phx-hook="SearchGlobalShortcut"
|
||||||
>
|
>
|
||||||
<span class="sr-only">{gettext("Search (Ctrl+K)")}</span>
|
<span class="sr-only">{gettext("Search (Ctrl+K)")}</span>
|
||||||
<.icon name="hero-magnifying-glass" class="h-5 w-5" />
|
<.icon name="hero-magnifying-glass" class="h-5 w-5" />
|
||||||
|
|||||||
@@ -201,7 +201,8 @@ defmodule MusicLibraryWeb.SearchComponents do
|
|||||||
<div class="p-8 text-center">
|
<div class="p-8 text-center">
|
||||||
<.icon name="hero-magnifying-glass" class="h-12 w-12 text-zinc-400 mx-auto mb-4" />
|
<.icon name="hero-magnifying-glass" class="h-12 w-12 text-zinc-400 mx-auto mb-4" />
|
||||||
<p class="text-sm text-zinc-500 dark:text-zinc-500 mt-2">
|
<p class="text-sm text-zinc-500 dark:text-zinc-500 mt-2">
|
||||||
{gettext("Search records and artists...")}
|
<kbd class="px-2 py-1 bg-zinc-100 dark:bg-zinc-700 rounded text-xs">Ctrl+K</kbd>
|
||||||
|
{gettext("to open this search")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1162,11 +1162,6 @@ msgstr ""
|
|||||||
msgid "Search (Ctrl+K)"
|
msgid "Search (Ctrl+K)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/search_components.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
|
||||||
msgid "Search records and artists..."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Artist image"
|
msgid "Artist image"
|
||||||
@@ -1176,3 +1171,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Artist updated successfully"
|
msgid "Artist updated successfully"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/search_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "to open this search"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -1162,11 +1162,6 @@ msgstr ""
|
|||||||
msgid "Search (Ctrl+K)"
|
msgid "Search (Ctrl+K)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/search_components.ex
|
|
||||||
#, elixir-autogen, elixir-format
|
|
||||||
msgid "Search records and artists..."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||||
#, elixir-autogen, elixir-format, fuzzy
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
msgid "Artist image"
|
msgid "Artist image"
|
||||||
@@ -1176,3 +1171,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format, fuzzy
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
msgid "Artist updated successfully"
|
msgid "Artist updated successfully"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/search_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "to open this search"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user