Browse Source

fix: close popup before redirecting

main
Inhji Y. 7 months ago
parent
commit
5c803561e4
  1. 23
      lib/mirage_web/live/goto_anything_live.ex

23
lib/mirage_web/live/goto_anything_live.ex

@ -31,14 +31,14 @@ defmodule MirageWeb.GotoAnythingLive do
selection = assigns.selection
socket =
if not Enum.empty?(results) do
if Enum.empty?(results) do
socket |> close_popup()
else
note = Enum.at(results, selection)
socket
|> push_redirect(to: Routes.note_show_path(socket, :show, note))
|> close_popup()
else
socket |> close_popup()
|> push_redirect(to: Routes.note_show_path(socket, :show, note))
end
{:noreply, socket}
@ -77,9 +77,10 @@ defmodule MirageWeb.GotoAnythingLive do
results = Enum.count(assigns.results)
selection =
cond do
selection >= results -> selection
true -> selection + 1
if selection >= results do
selection
else
selection + 1
end
socket |> assign(:selection, selection)
@ -87,12 +88,12 @@ defmodule MirageWeb.GotoAnythingLive do
defp dec_selection(%{assigns: assigns} = socket) do
selection = assigns.selection
results = Enum.count(assigns.results)
selection =
cond do
selection <= 0 -> selection
true -> selection - 1
if selection <= 0 do
selection
else
selection - 1
end
socket |> assign(:selection, selection)

Loading…
Cancel
Save