Skip to content

Commit

Permalink
implement fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
sawhney17 committed Jul 12, 2022
1 parent 0854028 commit 7ccc56b
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/main/frontend/components/reference.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[frontend.db.model :as model-db]
[frontend.handler.block :as block-handler]
[frontend.handler.page :as page-handler]
[frontend.search :as search]
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
Expand All @@ -18,11 +19,7 @@
(rum/defcs filter-dialog-inner < rum/reactive (rum/local "" ::filterSearch)
[state filters-atom _close-fn references page-name]
(let [filter-search (get state ::filterSearch)
filtered-references (filter (fn [ref]
(if (string/includes? (util/page-name-sanity-lc (ref 0)) (util/page-name-sanity-lc @filter-search)) true false))
references)]
(println filtered-references)
;; (println (search/fuzzy-search references (util/page-name-sanity-lc filter-search) :limit 20))
filtered-references (search/fuzzy-search references @filter-search :limit 20 :extract-fn (fn [arg] (arg 0)))]
[:div.filters
[:div.sm:flex.sm:items-start
[:div.mx-auto.flex-shrink-0.flex.items-center.justify-center.h-12.w-12.rounded-full.bg-gray-200.text-gray-500.sm:mx-0.sm:h-10.sm:w-10
Expand All @@ -32,10 +29,10 @@
[:span.text-xs
"Click to include and shift-click to exclude. Click again to remove."]]]
[:div.cp__filters-input-panel.flex (ui/icon "search") [:input.cp__filters-input.w-full
{:placeholder (t :filter/search)
:auto-focus true
:on-change (fn [e]
(reset! filter-search (util/evalue e)))}]]
{:placeholder (t :filter/search)
:auto-focus true
:on-change (fn [e]
(reset! filter-search (util/evalue e)))}]]
(when (seq filtered-references)
(let [filters (rum/react filters-atom)]
[:div.mt-5.sm:mt-4.sm:flex.sm.gap-1.flex-wrap
Expand All @@ -47,11 +44,11 @@
false "text-red-400"
nil)]
[:button.border.rounded.px-1.mb-1.mr-1.select-none {:key (reference 0) :class color :style {:border-color "currentColor"}
:on-click (fn [e]
(swap! filters-atom #(if (nil? (get filters lc-reference))
(assoc % lc-reference (not (.-shiftKey e)))
(dissoc % lc-reference)))
(page-handler/save-filter! page-name @filters-atom))}
:on-click (fn [e]
(swap! filters-atom #(if (nil? (get filters lc-reference))
(assoc % lc-reference (not (.-shiftKey e)))
(dissoc % lc-reference)))
(page-handler/save-filter! page-name @filters-atom))}
(reference 0) [:sub " " (reference 1)]]))]))]))

(defn filter-dialog
Expand Down

0 comments on commit 7ccc56b

Please sign in to comment.