mirror of
https://github.com/logseq/logseq.git
synced 2026-05-21 19:24:17 +00:00
fix: reactive queries
Each block should have its own :query-result atom
This commit is contained in:
committed by
Gabriel Horner
parent
096447db48
commit
8ab497cb8a
@@ -2734,9 +2734,7 @@
|
||||
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
|
||||
config (if (nil? (:query-result config))
|
||||
(assoc config :query-result (atom nil))
|
||||
config)
|
||||
config (assoc config :query-result (atom nil))
|
||||
config (if ref? (block-handler/attach-order-list-state config block) config)
|
||||
heading? (:heading properties)
|
||||
*control-show? (get state ::control-show?)
|
||||
@@ -2771,18 +2769,18 @@
|
||||
(state/sub-block-selected? blocks-container-id uuid))]
|
||||
[:div.ls-block
|
||||
(cond->
|
||||
{:id block-id
|
||||
:data-refs data-refs
|
||||
:data-refs-self data-refs-self
|
||||
:data-collapsed (and collapsed? has-child?)
|
||||
:class (str uuid
|
||||
(when pre-block? " pre-block")
|
||||
(when (and card? (not review-cards?)) " shadow-md")
|
||||
(when selected? " selected noselect")
|
||||
(when order-list? " is-order-list")
|
||||
(when (string/blank? content) " is-blank"))
|
||||
:blockid (str uuid)
|
||||
:haschild (str (boolean has-child?))}
|
||||
{:id block-id
|
||||
:data-refs data-refs
|
||||
:data-refs-self data-refs-self
|
||||
:data-collapsed (and collapsed? has-child?)
|
||||
:class (str uuid
|
||||
(when pre-block? " pre-block")
|
||||
(when (and card? (not review-cards?)) " shadow-md")
|
||||
(when selected? " selected noselect")
|
||||
(when order-list? " is-order-list")
|
||||
(when (string/blank? content) " is-blank"))
|
||||
:blockid (str uuid)
|
||||
:haschild (str (boolean has-child?))}
|
||||
|
||||
level
|
||||
(assoc :level level)
|
||||
|
||||
@@ -141,9 +141,7 @@
|
||||
(when-not (or built-in? dsl-query?)
|
||||
(when collapsed?
|
||||
(editor-handler/collapse-block! current-block-uuid))))
|
||||
state)}
|
||||
(rum/local nil ::query-result)
|
||||
{:init (fn [state] (assoc state :query-error (atom nil)))}
|
||||
(assoc state :query-error (atom nil)))}
|
||||
[state config {:keys [title builder query view collapsed? table-view?] :as q} *query-triggered?]
|
||||
(let [*query-error (:query-error state)
|
||||
built-in? (built-in-custom-query? title)
|
||||
@@ -208,13 +206,13 @@
|
||||
(if table?
|
||||
[:a.flex.ml-1.fade-link {:title "Switch to list view"
|
||||
:on-click (fn [] (editor-property/set-block-property! current-block-uuid
|
||||
"query-table"
|
||||
false))}
|
||||
"query-table"
|
||||
false))}
|
||||
(ui/icon "list" {:style {:font-size 20}})]
|
||||
[:a.flex.ml-1.fade-link {:title "Switch to table view"
|
||||
:on-click (fn [] (editor-property/set-block-property! current-block-uuid
|
||||
"query-table"
|
||||
true))}
|
||||
"query-table"
|
||||
true))}
|
||||
(ui/icon "table" {:style {:font-size 20}})]))
|
||||
|
||||
[:a.flex.ml-1.fade-link
|
||||
|
||||
@@ -61,26 +61,25 @@
|
||||
|
||||
(defn get-query-result
|
||||
[state config *query-error *query-triggered? current-block-uuid q options]
|
||||
(or (when-let [*result (:query-result config)] @*result)
|
||||
(let [query-atom (trigger-custom-query! state *query-error *query-triggered?)
|
||||
query-result (and query-atom (rum/react query-atom))
|
||||
(let [query-atom (trigger-custom-query! state *query-error *query-triggered?)
|
||||
query-result (and query-atom (rum/react query-atom))
|
||||
;; exclude the current one, otherwise it'll loop forever
|
||||
remove-blocks (if current-block-uuid [current-block-uuid] nil)
|
||||
transformed-query-result (when query-result
|
||||
(let [result (db/custom-query-result-transform query-result remove-blocks q)]
|
||||
(if (and query-result (coll? result) (:block/uuid (first result)))
|
||||
(cond-> result
|
||||
(get q :remove-block-children? true)
|
||||
tree/filter-top-level-blocks)
|
||||
result)))
|
||||
group-by-page? (get-group-by-page q options)
|
||||
result (if (and group-by-page? (:block/uuid (first transformed-query-result)))
|
||||
(let [result (db-utils/group-by-page transformed-query-result)]
|
||||
(if (map? result)
|
||||
(dissoc result nil)
|
||||
result))
|
||||
transformed-query-result)]
|
||||
(when-let [query-result (:query-result config)]
|
||||
(reset! query-result result))
|
||||
(when query-atom
|
||||
(util/safe-with-meta result (meta @query-atom))))))
|
||||
remove-blocks (if current-block-uuid [current-block-uuid] nil)
|
||||
transformed-query-result (when query-result
|
||||
(let [result (db/custom-query-result-transform query-result remove-blocks q)]
|
||||
(if (and query-result (coll? result) (:block/uuid (first result)))
|
||||
(cond-> result
|
||||
(get q :remove-block-children? true)
|
||||
tree/filter-top-level-blocks)
|
||||
result)))
|
||||
group-by-page? (get-group-by-page q options)
|
||||
result (if (and group-by-page? (:block/uuid (first transformed-query-result)))
|
||||
(let [result (db-utils/group-by-page transformed-query-result)]
|
||||
(if (map? result)
|
||||
(dissoc result nil)
|
||||
result))
|
||||
transformed-query-result)]
|
||||
(when-let [query-result (:query-result config)]
|
||||
(reset! query-result result))
|
||||
(when query-atom
|
||||
(util/safe-with-meta result (meta @query-atom)))))
|
||||
|
||||
Reference in New Issue
Block a user