neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
and uh I guess the search component too.
cfbf883 · gmorell · 2023-06-22 03:13
Files changed
added
apps/room_sanctum/lib/room_sanctum_web/components/search.ex
+64
−0
@@ -0,0 +1,64 @@
| 1 | +defmodule RoomSanctumWeb.SearchComponent do | |
| 2 | + import RoomSanctumWeb.CoreComponents | |
| 3 | + use Phoenix.Component | |
| 4 | + | |
| 5 | + @impl true | |
| 6 | + def render(assigns) do | |
| 7 | + ~H""" | |
| 8 | + qqq | |
| 9 | + """ | |
| 10 | + end | |
| 11 | + | |
| 12 | + attr :type, :string, required: true | |
| 13 | + attr :id, :any, default: nil | |
| 14 | + attr :name, :any | |
| 15 | + attr :label, :string, default: nil | |
| 16 | + attr :field, Phoenix.HTML.FormField, | |
| 17 | + doc: "a form field struct retrieved from the form, for example: @form[:email]" | |
| 18 | + | |
| 19 | + attr :label_field, :string, required: true | |
| 20 | + attr :value_field, :string, required: true | |
| 21 | + | |
| 22 | + def search_input(assigns) do | |
| 23 | + ~H""" | |
| 24 | + <.input field={@field} type="text" label={@label} phx-target={"##{@id}"} phx-keyup={"do-#{@type}-search"} phx-debounce="200" id={@id} /> | |
| 25 | + <ul class="menu bg-secondary"> | |
| 26 | + <%= for r <- @results |> Enum.slice(0..10) do %> | |
| 27 | + <li class="hover-bordered"> | |
| 28 | + <a class="text-secondary-content" phx-click={"set-#{@type}"} phx-target={"##{@id}"} phx-value-val={r |> Map.from_struct |> Map.get @value_field} phx-value-type={@type}> | |
| 29 | + <div class="flex justify-between w-full"> | |
| 30 | + <div><%= r |> Map.from_struct |> Map.get @label_field %></div> | |
| 31 | + <div class="badge badge-accent"><%= r |> Map.from_struct |> Map.get @value_field %></div> | |
| 32 | + </div> | |
| 33 | + </a> | |
| 34 | + </li> | |
| 35 | + <% end %> | |
| 36 | + </ul> | |
| 37 | + """ | |
| 38 | + end | |
| 39 | + | |
| 40 | + def results(assigns) do | |
| 41 | + ~H""" | |
| 42 | + """ | |
| 43 | + end | |
| 44 | + | |
| 45 | + def result_item(assigns) do | |
| 46 | + ~H""" | |
| 47 | + """ | |
| 48 | + end | |
| 49 | + | |
| 50 | + @impl true | |
| 51 | + def update(assigns, socket) do | |
| 52 | + {:ok, | |
| 53 | + socket | |
| 54 | + |> assign(assigns) | |
| 55 | + |> assign_new(:results, []) | |
| 56 | + |> assign_new(:query, "") | |
| 57 | + } | |
| 58 | + end | |
| 59 | + | |
| 60 | + def handle_event("do-search", params, socket) do | |
| 61 | + IO.puts("search") | |
| 62 | + {:noreply, socket} | |
| 63 | + end | |
| 64 | +end |
Parents: ff34b00