Skip to content

Commit

Permalink
Use fuzzy search for all search input. Fixes #383
Browse files Browse the repository at this point in the history
  • Loading branch information
madis committed Mar 12, 2024
1 parent 6477566 commit 2535694
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions ui/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

cljsjs/apollo-fetch {:mvn/version "0.7.0-0"}
cljsjs/graphql {:mvn/version "0.13.1-0"}
com.wsscode/fuzzy {:mvn/version "1.0.0"}
expound/expound {:mvn/version "0.8.4"}
flib/simplebar {:mvn/version "5.0.7-SNAPSHOT"}
funcool/bide {:mvn/version "1.7.0"} ; FIXME: district.ui.router requires it but older version is included by some other library
Expand Down
10 changes: 4 additions & 6 deletions ui/src/ethlance/ui/component/search_input.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns ethlance.ui.component.search-input
(:require
["react" :as react]
[com.wsscode.fuzzy :as fz]
[cuerdas.core :as string]
[ethlance.ui.component.icon :refer [c-icon]]
[reagent.core :as r]))
Expand All @@ -11,12 +12,9 @@

(defn filter-selections
[search-text selections label-fn]
(if (and (seq search-text) (seq selections))
(->> selections
(filter #(string/includes? (string/lower (label-fn %)) (string/lower search-text)))
vec)
nil))

(let [fuzzy-options (map (fn [sel] {::fz/string (label-fn sel)}) selections)]
(when (and (seq search-text) (seq selections))
(map ::fz/string (fz/fuzzy-match {::fz/search-input search-text ::fz/options fuzzy-options})))))

(defn next-element
"Get the next element in `xs` after element `v`."
Expand Down

0 comments on commit 2535694

Please sign in to comment.