|
@@ -45,56 +45,58 @@
|
|
|
(->> (:keywords library-item)
|
|
|
(string/join ", "))]]]]]])
|
|
|
|
|
|
+(defn- search-results [library search-term]
|
|
|
+ (let [sorted (partial sort-by (comp string/lower-case :name))]
|
|
|
+ (if-let [search (->> search-term
|
|
|
+ string/trim
|
|
|
+ string/lower-case
|
|
|
+ not-empty)]
|
|
|
+ (let [search-names (->> library
|
|
|
+ (filter #(string/includes? (string/lower-case (:name %)) search))
|
|
|
+ (set))
|
|
|
+ search-keywords (->> library
|
|
|
+ (filter (fn [item]
|
|
|
+ (some #(string/includes? (string/lower-case %) search) (:keywords item))))
|
|
|
+ (remove search-names)
|
|
|
+ (set))
|
|
|
+ search-categories (->> library
|
|
|
+ (filter (fn [item]
|
|
|
+ (some #(string/includes? (string/lower-case %) search) (:categories item))))
|
|
|
+ (remove search-names)
|
|
|
+ (remove search-keywords)
|
|
|
+ (set))]
|
|
|
+ (concat
|
|
|
+ (sorted search-names)
|
|
|
+ (sorted search-keywords)
|
|
|
+ (sorted search-categories)))
|
|
|
+ (sorted library))))
|
|
|
+
|
|
|
(defn task-selector [which]
|
|
|
(let [search-term (r/atom "")
|
|
|
library-data (re-frame/subscribe [::subs/library])]
|
|
|
(fn []
|
|
|
- (let [sorted (partial sort-by (comp string/lower-case :name))
|
|
|
- library (if-let [search (->> @search-term
|
|
|
- string/trim
|
|
|
- string/lower-case
|
|
|
- not-empty)]
|
|
|
- (let [search-names (->> @library-data
|
|
|
- (filter #(string/includes? (string/lower-case (:name %)) search))
|
|
|
- (set))
|
|
|
- search-keywords (->> @library-data
|
|
|
- (filter (fn [item]
|
|
|
- (some #(string/includes? (string/lower-case %) search) (:keywords item))))
|
|
|
- (remove search-names)
|
|
|
- (set))
|
|
|
- search-categories (->> @library-data
|
|
|
- (filter (fn [item]
|
|
|
- (some #(string/includes? (string/lower-case %) search) (:categories item))))
|
|
|
- (remove search-names)
|
|
|
- (remove search-keywords)
|
|
|
- (set))]
|
|
|
- (concat
|
|
|
- (sorted search-names)
|
|
|
- (sorted search-keywords)
|
|
|
- (sorted search-categories)))
|
|
|
- (sorted @library-data))]
|
|
|
- [re-com/modal-panel
|
|
|
- :backdrop-on-click #(re-frame/dispatch [::events/select-selecting nil])
|
|
|
- :child
|
|
|
- [re-com/scroller
|
|
|
- :v-scroll :auto
|
|
|
- :h-scroll :off
|
|
|
- :height "80vh"
|
|
|
- :child
|
|
|
- [re-com/v-box
|
|
|
- :gap "10px"
|
|
|
- :align :center
|
|
|
- :children
|
|
|
- (concat
|
|
|
- [[re-com/title
|
|
|
- :label "Select an Activity"
|
|
|
- :level :level3]
|
|
|
- [re-com/input-text
|
|
|
- :model search-term
|
|
|
- :change-on-blur? false
|
|
|
- :placeholder "search"
|
|
|
- :on-change #(reset! search-term %)]]
|
|
|
- (map
|
|
|
- (fn [library-item]
|
|
|
- [selection-item which library-item])
|
|
|
- library))]]]))))
|
|
|
+ [re-com/modal-panel
|
|
|
+ :backdrop-on-click #(re-frame/dispatch [::events/select-selecting nil])
|
|
|
+ :child
|
|
|
+ [re-com/scroller
|
|
|
+ :v-scroll :auto
|
|
|
+ :h-scroll :off
|
|
|
+ :height "80vh"
|
|
|
+ :child
|
|
|
+ [re-com/v-box
|
|
|
+ :gap "10px"
|
|
|
+ :align :center
|
|
|
+ :children
|
|
|
+ (concat
|
|
|
+ [[re-com/title
|
|
|
+ :label "Select an Activity"
|
|
|
+ :level :level3]
|
|
|
+ [re-com/input-text
|
|
|
+ :model search-term
|
|
|
+ :change-on-blur? false
|
|
|
+ :placeholder "search"
|
|
|
+ :on-change #(reset! search-term %)]]
|
|
|
+ (map
|
|
|
+ (fn [library-item]
|
|
|
+ [selection-item which library-item])
|
|
|
+ (search-results @library-data @search-term)))]]])))
|