Skip to content

Commit

Permalink
feat: show coref count
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jan 25, 2022
1 parent 59a29ac commit a8723b4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/cljc/athens/common_db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,16 @@
(throw (ex-info fail-msg position)))))


(defn page-refs
"Returns page titles referenced in eid."
[db eid]
(->> eid
(d/entity db)
:block/refs
(map :node/title)
(remove nil?)))


(defn extract-tag-values
"Extracts `tag` values from `children-fn` children with `extractor-fn` from parser AST."
[ast tag-selector children-fn extractor-fn]
Expand Down
1 change: 1 addition & 0 deletions src/cljs/athens/listeners.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
e2e-ignore-save? (= (js/localStorage.getItem "E2E_IGNORE_SAVE") "true")
remote? (electron-utils/remote-db? @(subscribe [:db-picker/selected-db]))]
(cond
#_#_
(and (or (not synced?)
(not (= nil editing?)))
(not @force-leave)
Expand Down
40 changes: 30 additions & 10 deletions src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
["/components/Block/components/Anchor" :refer [Anchor]]
["/components/Block/components/Toggle" :refer [Toggle]]
["/components/Button/Button" :refer [Button]]
[athens.common-db :as common-db]
[athens.common.logging :as log]
[athens.db :as db]
[athens.electron.images :as images]
Expand Down Expand Up @@ -111,16 +112,35 @@

;; Components

(def coref-string-size-limit 3)


;; TODO: show corefs in block view
(defn block-refs-count-el
[count uid]
[:div (stylefy/use-style {:margin-left "1em"
:grid-area "refs"
:z-index (:zindex-dropdown style/ZINDICES)
:visibility (when-not (pos? count) "hidden")})
[:> Button {:on-click (fn [e]
(.. e stopPropagation)
(rf/dispatch [:right-sidebar/open-item uid]))}
count]])
[refs uid]
(let [db @db/dsdb ;; TODO: this isn't reactive
total (count refs)
corefs (->> refs
(map :db/id)
(mapcat (partial common-db/page-refs db))
(remove #(> (count %) coref-string-size-limit))
(frequencies))]
(into
[:div (stylefy/use-style {:margin-left "1em"
:grid-area "refs"
:z-index (:zindex-dropdown style/ZINDICES)
:visibility (when-not (pos? total) "hidden")})]
(conj
(mapv (fn [[title total]]
[:> Button {:on-click (fn [e]
(.. e stopPropagation)
(rf/dispatch [:right-sidebar/open-item uid]))}
[:span title " " [:sub total]]])
corefs)
[:> Button {:on-click (fn [e]
(.. e stopPropagation)
(rf/dispatch [:right-sidebar/open-item uid]))}
total]))))


(defn block-drag-over
Expand Down Expand Up @@ -361,7 +381,7 @@
[presence/inline-presence-el uid]

(when (and (> (count _refs) 0) (not= :block-embed? opts))
[block-refs-count-el (count _refs) uid])]
[block-refs-count-el _refs uid])]

[autocomplete-search/inline-search-el block state]
[autocomplete-slash/slash-menu-el block state]
Expand Down

0 comments on commit a8723b4

Please sign in to comment.