|
214 | 214 | :margin-block-start "0"}]]})
|
215 | 215 |
|
216 | 216 |
|
| 217 | +(defn has-coref? |
| 218 | + [set {:block/keys [refs] :as backref}] |
| 219 | + (when (some set refs) |
| 220 | + backref)) |
| 221 | + |
| 222 | + |
217 | 223 | (defn inline-linked-refs-el
|
218 | 224 | [block state]
|
219 |
| - (let [refs (db/get-linked-block-references block)] |
| 225 | + (let [ref-filter (-> state deref :inline-refs/filter) |
| 226 | + block' (if (seq ref-filter) |
| 227 | + (update block :block/_refs #(vec (keep (partial has-coref? ref-filter) %))) |
| 228 | + block) |
| 229 | + refs (db/get-linked-block-references block')] |
220 | 230 | (when (not-empty refs)
|
221 | 231 | [:div (stylefy/use-style references-style {:key "Inline Linked References"})
|
222 | 232 | [:section
|
|
235 | 245 | (def coref-string-size-limit 3)
|
236 | 246 |
|
237 | 247 |
|
238 |
| -;; TODO: show corefs in block view |
239 | 248 | (defn block-refs-count-el
|
240 |
| - [refs click-fn] |
241 |
| - (let [db @db/dsdb ; TODO: this isn't reactive |
242 |
| - total (count refs) |
243 |
| - corefs (->> refs |
244 |
| - (map :db/id) |
245 |
| - (mapcat (partial common-db/page-refs db)) |
246 |
| - (remove #(> (count %) coref-string-size-limit)) |
247 |
| - (frequencies))] |
| 249 | + [backrefs click-fn] |
| 250 | + (let [total (count backrefs) |
| 251 | + coref-freqs (->> backrefs |
| 252 | + (mapcat :block/refs) |
| 253 | + (remove #(-> % :node/title not)) |
| 254 | + (remove #(> (count (:node/title %)) coref-string-size-limit)) |
| 255 | + (frequencies))] ; TODO: stable sort |
248 | 256 |
|
249 | 257 | [:div (stylefy/use-style {:margin-left "1em"
|
250 |
| - :grid-area "refs" |
251 |
| - :z-index (:zindex-dropdown style/ZINDICES) |
252 |
| - :visibility (when-not (pos? total) "hidden")}) |
| 258 | + :grid-area "refs" |
| 259 | + :z-index (:zindex-dropdown style/ZINDICES) |
| 260 | + :visibility (when-not (pos? total) "hidden")}) |
253 | 261 | (doall
|
254 |
| - (for [[title total] corefs] |
255 |
| - [:> Button {:on-click (fn [e] |
256 |
| - (.. e stopPropagation) |
257 |
| - (click-fn e))} |
| 262 | + (for [[{:node/keys [title] :as coref} total] coref-freqs] |
| 263 | + [:> Button {:key (str "coref-count-" title) |
| 264 | + :on-click (fn [e] |
| 265 | + (.. e stopPropagation) |
| 266 | + (click-fn e #{coref}))} |
258 | 267 | [:span title " " [:sub total]]]))
|
259 |
| - [:> Button {:on-click (fn [e] |
260 |
| - (.. e stopPropagation) |
261 |
| - (click-fn e))} |
| 268 | + [:> Button {:on-click (fn [e] |
| 269 | + (.. e stopPropagation) |
| 270 | + (click-fn e #{}))} |
262 | 271 | total]]))
|
263 | 272 |
|
264 | 273 |
|
|
416 | 425 | :show-editable-dom false
|
417 | 426 | :linked-ref/open (or (false? linked-ref) initial-open)
|
418 | 427 | :inline-refs/open false
|
| 428 | + :inline-refs/filter #{} |
419 | 429 | :inline-refs/states {}
|
420 | 430 | :block/uid uid})
|
421 | 431 | save-fn #(db/transact-state-for-uid (or original-uid uid) state)
|
|
502 | 512 | [presence/inline-presence-el uid]
|
503 | 513 |
|
504 | 514 | (when (and (> (count _refs) 0) (not= :block-embed? opts))
|
505 |
| - [block-refs-count-el _refs (fn [e] |
506 |
| - (if (.. e -shiftKey) |
507 |
| - (rf/dispatch [:right-sidebar/open-item uid]) |
508 |
| - (swap! state update :inline-refs/open not)))])] |
| 515 | + [block-refs-count-el _refs (fn [e new-filter] |
| 516 | + (let [{:inline-refs/keys [open filter]} @state] |
| 517 | + (if (.. e -shiftKey) |
| 518 | + ;; shift-click always opens the block on the sidebar |
| 519 | + (rf/dispatch [:right-sidebar/open-item uid]) |
| 520 | + (do |
| 521 | + ;; update the filter |
| 522 | + (swap! state assoc :inline-refs/filter new-filter) |
| 523 | + |
| 524 | + ;; toggle open unless we're already open and just switching filters |
| 525 | + (when-not (and open (not= filter new-filter)) |
| 526 | + (swap! state update :inline-refs/open not))))))])] |
509 | 527 |
|
510 | 528 | [autocomplete-search/inline-search-el block state]
|
511 | 529 | [autocomplete-slash/slash-menu-el block state]
|
|
0 commit comments