3 Commits

  1. 11
      CHANGELOG.md
  2. 10
      assets/js/app.js
  3. 21
      lib/mirage_web/live/goto_anything_live.ex
  4. 10
      lib/mirage_web/live/goto_anything_live.html.leex
  5. 2
      mix.exs

11
CHANGELOG.md

@ -5,6 +5,17 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.46.0](https://git.inhji.de/inhji/mirage/compare/v0.45.0...v0.46.0) (2021-02-20)
### Features:
* redirect to first note on ENTER
* focus query input on popup open
## [v0.45.0](https://git.inhji.de/inhji/mirage/compare/v0.44.2...v0.45.0) (2021-02-19)

10
assets/js/app.js

@ -20,10 +20,20 @@ import {LiveSocket} from "phoenix_live_view"
import TableSort from "tablesort"
const handledKeys = ["p"]
const Hooks = {}
Hooks.GotoAnything = {
updated() {
if (this.el.classList.contains("open")) {
const input = document.querySelector("#query")
input.focus()
}
}
}
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {
params: {_csrf_token: csrfToken},
hooks: Hooks,
metadata: {
keydown: (e, el) => {
if (handledKeys.includes(e.key))

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

10
lib/mirage_web/live/goto_anything_live.html.leex

@ -1,7 +1,11 @@
<div id="goto-anything" class="<%= @popup_class %>" phx-window-keydown="hotkey">
<div id="goto-anything" class="<%= @popup_class %>" phx-window-keydown="hotkey" phx-hook="GotoAnything">
<form action="#">
<input type="text" placeholder="Search for anything..." autofocus="true"
phx-keyup="search" phx-debounce="100">
<input id="query"
type="text"
placeholder="Search for anything..."
autocomplete="off"
phx-keyup="search"
phx-debounce="100">
</form>
<div class="results">

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.45.0"
@version "0.46.0"
def project do
[

Loading…
Cancel
Save