From 5e46d9eb7aa19b24a88675fff67c62af95ff8ae5 Mon Sep 17 00:00:00 2001 From: Weihua Lu Date: Fri, 4 Jun 2021 23:13:02 +0800 Subject: [PATCH] fix: refactor threading --- src/main/frontend/handler/editor.cljs | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index fdcddf288..26f322783 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -2796,15 +2796,6 @@ (util/forward-kill-word input) (state/set-edit-content! (state/get-edit-input-id) (.-value input)))) -(defn tree-seq-with-level - [branch? children root] - (let [walk (fn walk [level node] - (lazy-seq - (cons (assoc node :block/level level) - (when (branch? node) - (mapcat (partial walk (inc level)) (children node))))))] - (walk 1 root))) - (defn all-blocks-with-level "Return all blocks associated with correct level if :collapse? true, return without any collapsed children @@ -2821,22 +2812,19 @@ {:block e :level 2}]" [{:keys [collapse?] :or {collapse? false}}] (let [page (state/get-current-page)] - (cond->> + (->> (-> page (db/get-page-blocks-no-cache) (tree/blocks->vec-tree page)) - collapse? - (w/postwalk - (fn [x] - (if (and (map? x) (-> x :block/properties :collapsed)) - (assoc x :block/children []) - x))) + (#(if collapse? + (w/postwalk + (fn [x] + (if (and (map? x) (-> x :block/properties :collapsed)) + (assoc x :block/children []) x)) %) %)) - :default - (mapcat (fn [x] (tree-seq-with-level map? :block/children x))) + (mapcat (fn [x] (tree-seq map? :block/children x))) - :default (map (fn [x] (dissoc x :block/children)))))) (defn collapse-block! [block-id]