mirror of https://github.com/logseq/logseq
parent
977add22ff
commit
8cc194ce60
|
@ -465,6 +465,7 @@
|
||||||
nil)
|
nil)
|
||||||
react))))
|
react))))
|
||||||
|
|
||||||
|
;; FIXME: merge get-page-blocks and get-block-and-children to simplify the logic
|
||||||
(defn get-page-blocks
|
(defn get-page-blocks
|
||||||
([page]
|
([page]
|
||||||
(get-page-blocks (state/get-current-repo) page nil))
|
(get-page-blocks (state/get-current-repo) page nil))
|
||||||
|
|
|
@ -3334,30 +3334,36 @@
|
||||||
[{:keys [collapse? expanded? root-block] :or {collapse? false expanded? false root-block nil}}]
|
[{:keys [collapse? expanded? root-block] :or {collapse? false expanded? false root-block nil}}]
|
||||||
(when-let [page (or (state/get-current-page)
|
(when-let [page (or (state/get-current-page)
|
||||||
(date/today))]
|
(date/today))]
|
||||||
(let [blocks (-> page
|
(let [block? (util/uuid-string? page)
|
||||||
(db/get-page-blocks-no-cache)
|
block-id (or (and block? (uuid page)) root-block)
|
||||||
(tree/blocks->vec-tree page))]
|
blocks (if block-id
|
||||||
(cond->> blocks
|
(db/get-block-and-children (state/get-current-repo) block-id)
|
||||||
root-block
|
(db/get-page-blocks-no-cache page))
|
||||||
(map (fn find [root]
|
blocks (tree/blocks->vec-tree blocks (or block-id page))
|
||||||
(if (= root-block (:block/uuid root))
|
root-block (or block-id root-block)]
|
||||||
root
|
(->>
|
||||||
(first (filter find (:block/children root []))))))
|
(cond->> blocks
|
||||||
|
root-block
|
||||||
|
(map (fn find [root]
|
||||||
|
(if (= root-block (:block/uuid root))
|
||||||
|
root
|
||||||
|
(first (filter find (:block/children root []))))))
|
||||||
|
|
||||||
collapse?
|
collapse?
|
||||||
(w/postwalk
|
(w/postwalk
|
||||||
(fn [b]
|
(fn [b]
|
||||||
(if (and (map? b) (-> b :block/properties :collapsed))
|
(if (and (map? b) (-> b :block/properties :collapsed))
|
||||||
(assoc b :block/children []) b)))
|
(assoc b :block/children []) b)))
|
||||||
|
|
||||||
true
|
true
|
||||||
(mapcat (fn [x] (tree-seq map? :block/children x)))
|
(mapcat (fn [x] (tree-seq map? :block/children x)))
|
||||||
|
|
||||||
expanded?
|
expanded?
|
||||||
(filter (fn [b] (collapsable? (:block/uuid b))))
|
(filter (fn [b] (collapsable? (:block/uuid b))))
|
||||||
|
|
||||||
true
|
true
|
||||||
(map (fn [x] (dissoc x :block/children)))))))
|
(map (fn [x] (dissoc x :block/children))))
|
||||||
|
(remove nil?)))))
|
||||||
|
|
||||||
(defn collapse-block! [block-id]
|
(defn collapse-block! [block-id]
|
||||||
(when (collapsable? block-id)
|
(when (collapsable? block-id)
|
||||||
|
|
Loading…
Reference in New Issue