You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.1 KiB

defmodule MirageWeb.GotoAnythingLive do
use MirageWeb, :live_view
@impl true
def mount(_params, _session, socket) do
{:ok, socket |> assign(%{popup_class: "closed", results: []})}
end
@impl true
def handle_event("hotkey", %{"key" => "p", "ctrlKey" => true}, socket) do
{:noreply, socket |> assign(%{popup_class: "open"})}
end
@impl true
def handle_event("hotkey", %{"key" => "Escape", "ctrlKey" => false}, socket) do
{:noreply, socket |> assign(%{popup_class: "closed"})}
end
@impl true
def handle_event("hotkey", _params, socket) do
{:noreply, socket}
end
@impl true
def handle_event("search", %{"key" => "Enter", "value" => _}, socket) do
results = socket.assigns.results
socket =
if not Enum.empty?(results) do
note = List.first(results)
push_redirect(socket, to: Routes.note_show_path(socket, :show, note))
else
socket
end
{:noreply, socket}
end
@impl true
def handle_event("search", %{"key" => _, "value" => query}, socket) do
results = Mirage.Notes.search_notes(query)
{:noreply, socket |> assign(%{results: results})}
end
end