Browse Source

feat: redirect to first note on ENTER

main
Inhji Y. 4 months ago
parent
commit
fc48c213f5
  1. 21
      lib/mirage_web/live/goto_anything_live.ex

21
lib/mirage_web/live/goto_anything_live.ex

@ -20,7 +20,26 @@ defmodule MirageWeb.GotoAnythingLive do
@impl true
def handle_event("hotkey", params, socket) do
IO.inspect(params)
{: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)
IO.inspect("Redirecting to #{note.title}")
push_redirect(socket,
to: Routes.live_path(MirageWeb.Endpoint, MirageWeb.ShowNoteLive, note.id)
)
else
socket
end
{:noreply, socket}
end

Loading…
Cancel
Save