Refactored hairy block component by breaking out logical fns

pull/9520/head^2
Gabriel Horner 2023-06-16 21:43:43 -04:00 committed by Gabriel Horner
parent cb29fb6eae
commit f82bbb5275
2 changed files with 40 additions and 27 deletions

View File

@ -2705,16 +2705,27 @@
(= (:id config) (= (:id config)
(str (:block/uuid block))))) (str (:block/uuid block)))))
(rum/defc ^:large-vars/cleanup-todo block-container-inner < rum/reactive db-mixins/query (defn- build-config [config block {:keys [navigating-block navigated?]}]
[state repo config block] (cond-> config
(let [ref? (:ref? config) navigated?
custom-query? (boolean (:custom-query? config)) (assoc :id (str navigating-block))
ref-or-custom-query? (or ref? custom-query?)
*navigating-block (get state ::navigating-block) true
navigating-block (rum/react *navigating-block) (update :block merge block)
navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
block (if (or (and custom-query? ;; Each block might have multiple queries, but we store only the first query's result.
(empty? (:block/children block)) ;; This :query-result atom is used by the query function feature to share results between
;; the parent's query block and the children blocks. This works because config is shared
;; between parent and children blocks
(nil? (:query-result config))
(assoc :query-result (atom nil))
(:ref? config)
(block-handler/attach-order-list-state block)))
(defn- build-block [repo config block* {:keys [navigating-block navigated?]}]
(let [block (if (or (and (:custom-query? config)
(empty? (:block/children block*))
(not (and (:dsl-query? config) (not (and (:dsl-query? config)
(string/includes? (:query config) "not")))) (string/includes? (:query config) "not"))))
navigated?) navigated?)
@ -2723,24 +2734,26 @@
{:scoped-block-id (:db/id block)}) {:scoped-block-id (:db/id block)})
tree (tree/blocks->vec-tree blocks (:block/uuid (first blocks)))] tree (tree/blocks->vec-tree blocks (:block/uuid (first blocks)))]
(first tree)) (first tree))
block) block*)
block (if ref? {:block/keys [pre-block? format content] :as block'}
(if (:ref? config)
(merge block (db/sub-block (:db/id block))) (merge block (db/sub-block (:db/id block)))
block) block)]
{:block/keys [uuid children pre-block? refs level format content properties]} block (merge block' (block/parse-title-and-body uuid format pre-block? content))))
(rum/defc ^:large-vars/cleanup-todo block-container-inner < rum/reactive db-mixins/query
[state repo config* block*]
(let [ref? (:ref? config*)
custom-query? (boolean (:custom-query? config*))
ref-or-custom-query? (or ref? custom-query?)
*navigating-block (get state ::navigating-block)
navigating-block (rum/react *navigating-block)
navigated? (and (not= (:block/uuid block*) navigating-block) navigating-block)
block (build-block repo config* block* {:navigating-block navigating-block :navigated? navigated?})
{:block/keys [uuid children pre-block? refs level content properties]} block
{:block.temp/keys [top?]} block {:block.temp/keys [top?]} block
config (if navigated? (assoc config :id (str navigating-block)) config) config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
block (merge block (block/parse-title-and-body uuid format pre-block? content))
blocks-container-id (:blocks-container-id config) blocks-container-id (:blocks-container-id config)
config (update config :block merge block)
;; Each block might have multiple queries, but we store only the first query's result.
;; This :query-result atom is used by the query function feature to share results between
;; the parent's query block and the children blocks. This works because config is shared
;; between parent and children blocks
config (if (nil? (:query-result config))
(assoc config :query-result (atom nil))
config)
config (if ref? (block-handler/attach-order-list-state config block) config)
heading? (:heading properties) heading? (:heading properties)
*control-show? (get state ::control-show?) *control-show? (get state ::control-show?)
db-collapsed? (util/collapsed? block) db-collapsed? (util/collapsed? block)