fix(elixir): search not working
This commit is contained in:
@@ -59,21 +59,27 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
|
||||
@impl true
|
||||
def handle_event("search", %{"search" => search}, socket) do
|
||||
query_string = build_query_params(socket, %{search: search})
|
||||
path = if query_string == "", do: "/", else: "/?" <> query_string
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:search, search)
|
||||
|> assign(:offset, 0)
|
||||
|> load_components()
|
||||
|> push_patch(to: ~p"/?#{build_query_params(socket, %{search: search})}")}
|
||||
|> push_patch(to: path)}
|
||||
end
|
||||
|
||||
def handle_event("sort_change", %{"sort_criteria" => criteria}, socket) do
|
||||
query_string = build_query_params(socket, %{criteria: criteria})
|
||||
path = if query_string == "", do: "/", else: "/?" <> query_string
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:sort_criteria, criteria)
|
||||
|> assign(:offset, 0)
|
||||
|> load_components()
|
||||
|> push_patch(to: ~p"/?#{build_query_params(socket, %{criteria: criteria})}")}
|
||||
|> push_patch(to: path)}
|
||||
end
|
||||
|
||||
def handle_event("category_filter", %{"category_id" => ""}, socket) do
|
||||
@@ -260,7 +266,11 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
limit: @items_per_page,
|
||||
offset: socket.assigns.offset
|
||||
]
|
||||
|> Enum.reject(fn {_k, v} -> is_nil(v) end)
|
||||
|> Enum.reject(fn
|
||||
{_, v} when is_nil(v) -> true
|
||||
{:search, v} when v == "" -> true
|
||||
{_, _} -> false
|
||||
end)
|
||||
|
||||
%{components: new_components, has_more: has_more} =
|
||||
Inventory.paginate_components(filters)
|
||||
|
||||
Reference in New Issue
Block a user