Skip to content

Commit

Permalink
fix: filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 12, 2021
1 parent 43f127f commit 0fee13b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
16 changes: 10 additions & 6 deletions src/main/frontend/components/reference.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
(when (seq references)
[:div.mt-5.sm:mt-4.sm:flex.sm.gap-1.flex-wrap
(for [reference references]
(let [filtered (get (rum/react filter-state) reference)
(let [lc-reference (string/lower-case reference)
filtered (get (rum/react filter-state) lc-reference)
color (condp = filtered
true "text-green-400"
false "text-red-400"
nil)]
[:button.border.rounded.px-1.mb-1 {:key reference :class color :style {:border-color "currentColor"}
[:button.border.rounded.px-1.mb-1.mr-1 {:key reference :class color :style {:border-color "currentColor"}
:on-click (fn [e]
(swap! filter-state #(if (nil? (get @filter-state reference))
(assoc % reference (not (.-shiftKey e)))
(dissoc % reference)))
(swap! filter-state #(if (nil? (get @filter-state lc-reference))
(assoc % lc-reference (not (.-shiftKey e)))
(dissoc % lc-reference)))
(page-handler/save-filter! page-name @filter-state))}
reference]))])]))

Expand All @@ -67,13 +68,16 @@
(db/get-block-referenced-blocks block-id)
:else
(db/get-page-referenced-blocks page-name))
ref-pages (map (comp :block/original-name first) ref-blocks)
scheduled-or-deadlines (if (and journal?
(not (true? (state/scheduled-deadlines-disabled?)))
(= page-name (string/lower-case (date/journal-name))))
(db/get-date-scheduled-or-deadlines (string/capitalize page-name))
nil)
references (db/get-page-linked-refs-refed-pages repo page-name)
_ (def xx references)
references (->> (concat ref-pages references)
(remove nil?)
(distinct))
filters (page-handler/get-filters page-name)
filter-state (rum/react filters)
filters (when (seq filter-state)
Expand Down
8 changes: 3 additions & 5 deletions src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@
:where
[?file :file/path ?path]
[(?pred $ ?path)]
[?block :block/file ?file]
[(missing? $ ?block :block/name)]]
[?block :block/file ?file]]
(conn/get-conn repo-url) pred)
db-utils/seq-flatten)))

Expand All @@ -183,8 +182,7 @@
:in $ ?path
:where
[?file :file/path ?path]
[?block :block/file ?file]
[(missing? $ ?block :block/name)]]
[?block :block/file ?file]]
(conn/get-conn repo-url) path)
db-utils/seq-flatten))

Expand Down Expand Up @@ -782,7 +780,7 @@
[?b :block/path-refs ?p]
[?b :block/refs ?other-p]
[(not= ?p ?other-p)]
[?other-p :block/name ?ref-page]]
[?other-p :block/original-name ?ref-page]]
conn
rules
page)
Expand Down
13 changes: 9 additions & 4 deletions src/main/frontend/handler/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
(mapcat last ref-blocks)
ref-blocks)
(mapcat (fn [b] (concat (:block/refs b) (:block/children-refs b))))
(concat (when group-by-page? (map first ref-blocks)))
(distinct)
(map :db/id)
(db/pull-many repo '[:db/id :block/name]))
Expand All @@ -74,15 +75,19 @@
(seq exclude-ids)
(remove (fn [block]
(let [ids (set (concat (map :db/id (:block/refs block))
(map :db/id (:block/children-refs block))))]
(map :db/id (:block/children-refs block))
[(:db/id (:block/page block))]))]
(seq (set/intersection exclude-ids ids)))))

(seq include-ids)
(remove (fn [block]
(let [ids (set (concat (map :db/id (:block/refs block))
(let [page-block-id (:db/id (:block/page block))
ids (set (concat (map :db/id (:block/refs block))
(map :db/id (:block/children-refs block))))]
(empty? (set/intersection include-ids ids)))))
))]
(if (and (contains? include-ids page-block-id)
(= 1 (count include-ids)))
(not= page-block-id (first include-ids))
(empty? (set/intersection include-ids (set (conj ids page-block-id))))))))))]
(if group-by-page?
(->> (map (fn [[p ref-blocks]]
[p (filter-f ref-blocks)]) ref-blocks)
Expand Down

0 comments on commit 0fee13b

Please sign in to comment.