5 Commits

  1. 15
      CHANGELOG.md
  2. 3
      lib/mirage/notes.ex
  3. 9
      lib/mirage_web/live/goto_anything_live.ex
  4. 5
      lib/mirage_web/live/goto_anything_live.html.leex
  5. 2
      mix.exs

15
CHANGELOG.md

@ -5,6 +5,21 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.51.0](https://git.inhji.de/inhji/mirage/compare/v0.50.0...v0.51.0) (2021-02-21)
### Features:
* order search results by views
### Bug Fixes:
* trigger search on keydown rather than keyup
* wrong path helpers
## [v0.50.0](https://git.inhji.de/inhji/mirage/compare/v0.49.0...v0.50.0) (2021-02-21)

3
lib/mirage/notes.ex

@ -30,7 +30,8 @@ defmodule Mirage.Notes do
select: n,
preload: ^@note_preloads,
where: contains(n.content, ^query),
or_where: contains(n.title, ^query)
or_where: contains(n.title, ^query),
order_by: [:views]
Repo.all(q)
end

9
lib/mirage_web/live/goto_anything_live.ex

@ -8,18 +8,16 @@ defmodule MirageWeb.GotoAnythingLive do
@impl true
def handle_event("hotkey", %{"key" => "p", "ctrlKey" => true}, socket) do
IO.inspect("Open Popup")
{:noreply, socket |> assign(%{popup_class: "open"})}
end
@impl true
def handle_event("hotkey", %{"key" => "Escape", "ctrlKey" => false}, socket) do
IO.inspect("Close Popup")
{:noreply, socket |> assign(%{popup_class: "closed"})}
end
@impl true
def handle_event("hotkey", params, socket) do
def handle_event("hotkey", _params, socket) do
{:noreply, socket}
end
@ -30,10 +28,7 @@ defmodule MirageWeb.GotoAnythingLive do
socket =
if not Enum.empty?(results) do
note = List.first(results)
IO.inspect("Redirecting to #{note.title}")
push_redirect(socket, to: Routes.show_note_path(@socket, :show, note))
push_redirect(socket, to: Routes.note_show_path(socket, :show, note))
else
socket
end

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

@ -4,7 +4,7 @@
type="text"
placeholder="Search for anything..."
autocomplete="off"
phx-keyup="search"
phx-keydown="search"
phx-debounce="100">
</form>
@ -19,11 +19,10 @@
<div class="card result">
<strong><%= note.title %></strong>
<div>
<%= live_redirect "Go to Note", to: Routes.live_path(MirageWeb.Endpoint, MirageWeb.ShowNoteLive, note.id) %>
<%= live_redirect "Go to Note", to: Routes.note_show_path(@socket, :show, note.id) %>
</div>
</div>
<% end %>
<% end %>
</div>
</div>

2
mix.exs

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

Loading…
Cancel
Save