diff --git a/lib/accumulator_web/components/notes_components.ex b/lib/accumulator_web/components/notes_components.ex index 92d9f5a..ac67fbe 100644 --- a/lib/accumulator_web/components/notes_components.ex +++ b/lib/accumulator_web/components/notes_components.ex @@ -82,4 +82,27 @@ defmodule AccumulatorWeb.NotesComponents do """ end + + def note_input(assigns) do + ~H""" +
+ + <.error :for={msg <- @errors}><%= msg %> +
+ """ + end end diff --git a/lib/accumulator_web/live/notes_live/notes_live.ex b/lib/accumulator_web/live/notes_live/notes_live.ex index b0e8036..61fe179 100644 --- a/lib/accumulator_web/live/notes_live/notes_live.ex +++ b/lib/accumulator_web/live/notes_live/notes_live.ex @@ -131,8 +131,24 @@ defmodule AccumulatorWeb.NotesLive do end def handle_event("search-submit", %{"search" => search} = _params, socket) do - # TODO: implement search functionality - IO.inspect(search, label: "Search") + search_term = String.trim(search) + search_term_length = String.length(search_term) + + socket = + if search_term_length != 0 do + notes = Notes.search(search_term) + + socket |> stream(:notes, notes, reset: true) |> push_event("new-note-scroll", %{}) + else + {notes, pagination_date} = + Notes.get_notes_grouped_and_ordered_by_date(Date.utc_today()) + + socket + |> stream(:notes, notes, reset: true) + |> assign(pagination_date: pagination_date) + |> push_event("new-note-scroll", %{}) + end + {:noreply, socket} end diff --git a/lib/accumulator_web/live/notes_live/notes_live.html.heex b/lib/accumulator_web/live/notes_live/notes_live.html.heex index af9f090..8276872 100644 --- a/lib/accumulator_web/live/notes_live/notes_live.html.heex +++ b/lib/accumulator_web/live/notes_live/notes_live.html.heex @@ -1,11 +1,18 @@
- <%!-- <.simple_form for={@search} phx-change="search-change" phx-submit="search-submit"> - <.input field={@search[:search]} class="bg-transparent" /> - --%> - Search bar(TODO) + <.simple_form for={@search} phx-change="search-change" phx-submit="search-submit"> +
+ <.note_input + label="Search" + field={@search[:search]} + class="bg-transparent bg-green-400" + id="search-input" + /> +
+
-