This just shows I need to dig more.
Before I get into that reasoning, my task was to be able to make a search bar that searched for names and also email addresses. Since some of our projects are so large it is
easier to search by a company name.
Initially this was daunting, how in the world do I display an email much less search for it?
Display
Well this part was not too bad. Because we code so well we have a “loop” for each member being displayed, now I just had to get their email and dis play it next to their name.
;from this
(:name user)
;to this
(str (:name user) "\n" (:email user))
That wasn’t so tough to display.
Search
Now, this was the slightly scarier part.
How can I search and filter by an email?
Well, most of the search bars were calling this function.
(defn filter-by-name [query entities]
(sorted-filter-by query entities [:name]))
I figured, this looks promising. What If I added :email
to this list as well?
(defn some-component []
(let [search-query (reagent/atom "")
filtered-users (reagent/track #(fuzzy/sorted-filter-by @search-query users [:email :name]))])
)
It turns out, this was a brilliant idea. Not a bad day.
Best,
Merl