Browse Source

refactor: improve save-block! method

charlie 4 years ago
parent
commit
e8a20dbde7
2 changed files with 10 additions and 6 deletions
  1. 2 2
      src/main/frontend/db/model.cljs
  2. 8 4
      src/main/frontend/handler/editor.cljs

+ 2 - 2
src/main/frontend/db/model.cljs

@@ -269,8 +269,8 @@
        (:file/content (d/entity (d/db conn) [:file/path path]))))))
 
 (defn get-block-by-uuid
-  [uuid]
-  (db-utils/entity [:block/uuid uuid]))
+  [id]
+  (db-utils/entity [:block/uuid (if (uuid? id) id (uuid id))]))
 
 (defn get-page-format
   [page-name]

+ 8 - 4
src/main/frontend/handler/editor.cljs

@@ -1419,10 +1419,14 @@
                              opts))))
 
 (defn save-block!
-  [{:keys [format block id repo dummy?] :as state} value]
-  (when (or (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
-            dummy?)
-    (save-block-aux! block value format {})))
+  ([repo uuid content]
+   (let [block (db-model/get-block-by-uuid uuid)
+         format (:block/format block)]
+     (save-block! {:block block :repo repo :format format} content)))
+  ([{:keys [format block repo dummy?] :as state} value]
+   (when (or (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
+             dummy?)
+     (save-block-aux! block value format {}))))
 
 (defn save-current-block-when-idle!
   ([]