Save and use previous query when filtering items

This commit is contained in:
Harshad Sharma 2024-05-19 07:29:33 +05:30
parent 699cd61e0e
commit 2781748626

View file

@ -54,7 +54,7 @@ defmodule FreediveWeb.LiliformLive do
)
searched_items = search(filtered_items, query)
socket = assign(socket, :items, searched_items)
socket = assign(socket, %{items: searched_items, query: query})
socket =
case Kernel.length(Map.keys(searched_items)) == 1 do
@ -73,8 +73,9 @@ defmodule FreediveWeb.LiliformLive do
def(handle_event("filter", %{"key" => key}, socket)) do
key = String.to_existing_atom(key)
items = FreediveWeb.LiliformLive.filter(socket.assigns.items_all, key)
socket = assign(socket, :items, items)
filtered_items = FreediveWeb.LiliformLive.filter(socket.assigns.items_all, key)
searched_items = search(filtered_items, socket.assigns.query)
socket = assign(socket, :items, searched_items)
socket =
assign(