Browse Source

fix: indent/outdent blocks not updated

Tienson Qin 3 years ago
parent
commit
d1c6d4ce88
2 changed files with 13 additions and 12 deletions
  1. 2 6
      src/main/frontend/components/block.cljs
  2. 11 6
      src/main/frontend/db/react.cljs

+ 2 - 6
src/main/frontend/components/block.cljs

@@ -2271,11 +2271,7 @@
         embed? (:embed? config)
         reference? (:reference? config)
         block-id (str "ls-block-" blocks-container-id "-" uuid)
-        has-child? (boolean
-                    (and
-                     (not pre-block?)
-                     (coll? children)
-                     (seq children)))
+        has-child? (first (:block/_parent (db/entity (:db/id block))))
         attrs (on-drag-and-mouse-attrs block uuid top? block-id *move-to)
         children-refs (get-children-refs children)
         data-refs (build-refs-data-value children-refs)
@@ -2371,7 +2367,7 @@
         ref? (:ref? config)
         custom-query? (boolean (:custom-query? config))
         ref-or-custom-query? (or ref? custom-query?)]
-    (if ref-or-custom-query?
+    (if (and ref-or-custom-query? (not (:ref-child? config)))
       (let [*visible? (::visible? state)]
         (ui/lazy-visible
          *visible?

+ 11 - 6
src/main/frontend/db/react.cljs

@@ -216,9 +216,8 @@
 
 (defn get-affected-queries-keys
   "Get affected queries through transaction datoms."
-  [{:keys [tx-data]}]
+  [{:keys [tx-data tx-meta db-before]}]
   {:post [(s/valid? ::affected-keys %)]}
-
   (let [blocks (->> (filter (fn [datom] (contains? #{:block/left :block/parent :block/page} (:a datom))) tx-data)
                     (map :v)
                     (distinct))
@@ -240,9 +239,15 @@
                                              (:db/id (:block/page block)))
                                     blocks [[::block (:block/uuid block)]]
                                     others (when page-id
-                                             [[::page-blocks page-id]
-                                              [::page->pages page-id]
-                                              [::block-direct-children (:block/uuid (:block/parent block))]])]
+                                             (let [db-after-parent-uuid (:block/uuid (:block/parent block))
+                                                   db-before-parent-uuid (:block/uuid (:block/parent (d/entity db-before
+                                                                                                               [:block/uuid (:block/uuid block)])))]
+                                               [[::page-blocks page-id]
+                                                [::page->pages page-id]
+                                                [::block-direct-children db-after-parent-uuid]
+                                                (when (and db-before-parent-uuid
+                                                           (not= db-before-parent-uuid db-after-parent-uuid))
+                                                  [::block-direct-children db-before-parent-uuid])]))]
                                 (concat blocks others)))))
                         blocks)
 
@@ -255,7 +260,7 @@
                                 (if (:block/name entity) ; page
                                   [::page-blocks ref]
                                   [::page-blocks (:db/id (:block/page entity))])))
-                            refs))
+                         refs))
         others (->>
                 (keys @query-state)
                 (filter (fn [ks]