Add page search

This commit is contained in:
Harshad Sharma 2024-05-16 05:17:37 +05:30
parent a4e04e3980
commit f2d02bb225
3 changed files with 15 additions and 7 deletions

View file

@ -3,7 +3,7 @@ defmodule FreediveWeb.LiliformLive do
quote location: :keep, bind_quoted: [opts: opts] do quote location: :keep, bind_quoted: [opts: opts] do
use FreediveWeb, :live_view use FreediveWeb, :live_view
@behaviour FreediveWeb.LiliformLive @behaviour FreediveWeb.LiliformLive
@all [ @filters_all [
%{ %{
title: "All", title: "All",
icon: "all", icon: "all",
@ -12,13 +12,21 @@ defmodule FreediveWeb.LiliformLive do
] ]
def(mount(_params, _session, socket)) do def(mount(_params, _session, socket)) do
items = items()
socket = assign(socket, :opts, Keyword.get(unquote(opts), :opts, [])) socket = assign(socket, :opts, Keyword.get(unquote(opts), :opts, []))
socket = assign(socket, :items, items()) socket = assign(socket, :items_all, items)
socket = assign(socket, :filters, @all ++ filters()) socket = assign(socket, :items, items)
socket = assign(socket, :filters, @filters_all ++ filters())
socket = assign(socket, :query, "") socket = assign(socket, :query, "")
IO.inspect(socket, label: "socket")
{:ok, socket} {:ok, socket}
end end
def(handle_event("search", %{"value" => query}, socket)) do
items = search(query)
socket = assign(socket, :items, items)
{:noreply, socket}
end
end end
end end

View file

@ -4,8 +4,8 @@ defmodule FreediveWeb.ServiceLive do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<.block class="px-2 py-4"> <.block class="px-2 py-4">
<.page name="Services"> <.page name="Services" filters={@filters}>
<FreediveWeb.ServiceLive.Item.item_block items={@items} /> <FreediveWeb.ServiceLive.Item.items_block items={@items} />
</.page> </.page>
</.block> </.block>
""" """
@ -82,7 +82,7 @@ defmodule FreediveWeb.ServiceLive.Item do
""" """
attr :items, :list, default: [], doc: "items" attr :items, :list, default: [], doc: "items"
def item_block(assigns) do def items_block(assigns) do
~H""" ~H"""
<%= for item <- @items do %> <%= for item <- @items do %>
<.link patch={item.path} class="panel-block pt-1"> <.link patch={item.path} class="panel-block pt-1">

View file

@ -42,7 +42,7 @@ defmodule Liliform.Page do
<.panel_block> <.panel_block>
<.control has-icons-left> <.control has-icons-left>
<input class="input is-info" type="text" placeholder="Search" name="search" value={@query} /> <input class="input is-info" type="text" placeholder="Search" name="search" value={@query} phx-keyup="search" />
<.icon for="search" size="1.5rem" aria-hidden="true" is-left /> <.icon for="search" size="1.5rem" aria-hidden="true" is-left />
</.control> </.control>
</.panel_block> </.panel_block>