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)
(str (:block/uuid block)))))
(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 (if (or (and custom-query?
(empty? (:block/children block))
(defn- build-config [config block {:keys [navigating-block navigated?]}]
(cond-> config
navigated?
(assoc :id (str navigating-block))
true
(update :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
(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)
(string/includes? (:query config) "not"))))
navigated?)
@ -2723,24 +2734,26 @@
{:scoped-block-id (:db/id block)})
tree (tree/blocks->vec-tree blocks (:block/uuid (first blocks)))]
(first tree))
block)
block (if ref?
(merge block (db/sub-block (:db/id block)))
block)
{:block/keys [uuid children pre-block? refs level format content properties]} block
block*)
{:block/keys [pre-block? format content] :as block'}
(if (:ref? config)
(merge block (db/sub-block (:db/id block)))
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
config (if navigated? (assoc config :id (str navigating-block)) config)
block (merge block (block/parse-title-and-body uuid format pre-block? content))
config (build-config config* block {:navigated? navigated? :navigating-block navigating-block})
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)
*control-show? (get state ::control-show?)
db-collapsed? (util/collapsed? block)

View File

@ -84,4 +84,4 @@
(when-let [query-result (:query-result config)]
(reset! query-result result))
(when query-atom
(util/safe-with-meta result (meta @query-atom)))))
(util/safe-with-meta result (meta @query-atom)))))