Explorar el Código

enhance: run custom queries immediately if editing in a query component

Tienson Qin hace 3 años
padre
commit
e848dbf9f8

+ 4 - 1
src/main/frontend/db/react.cljs

@@ -310,9 +310,12 @@
               (when (or query query-fn)
                 (try
                   (let [f #(execute-query! repo-url db k tx cache)]
+                    (f)
+                    ;; Detects whether user is editing in a custom query, if so, execute the query immediately
                     (if (and custom?
                              ;; modifying during cards review need to be executed immediately
-                             (not (:cards-query? (meta query))))
+                             (not (:cards-query? (meta query)))
+                             (not (state/edit-in-query-component)))
                       (async/put! (state/get-reactive-custom-queries-chan) [f query])
                       (f)))
                   (catch js/Error e

+ 2 - 2
src/main/frontend/handler/editor.cljs

@@ -2044,7 +2044,7 @@
           parent-block (db/pull parent)
           left (:db/id (:block/left editing-block))
           left-block (db/pull left)
-          [_ _ config] (state/get-editor-args)
+          config (last (state/get-editor-args))
           block-id (:block/uuid editing-block)
           block-self? (block-self-alone-when-insert? config block-id)
           has-children? (db/has-children? (state/get-current-repo)
@@ -3441,7 +3441,7 @@
 
 (defn- skip-collapsing-in-db?
   []
-  (let [config (:config (state/get-editor-args))]
+  (let [config (last (state/get-editor-args))]
     (:ref? config)))
 
 (defn- set-blocks-collapsed!

+ 6 - 0
src/main/frontend/state.cljs

@@ -1636,3 +1636,9 @@
 (defn get-modal-id
   []
   (:modal/id @state))
+
+(defn edit-in-query-component
+  []
+  (and (editing?)
+       ;; config
+       (:custom-query? (last (get-editor-args)))))