Procházet zdrojové kódy

chore: simplify save-excalidraw!

Yukun Guo před 5 roky
rodič
revize
4927802f21
1 změnil soubory, kde provedl 16 přidání a 18 odebrání
  1. 16 18
      src/main/frontend/handler/draw.cljs

+ 16 - 18
src/main/frontend/handler/draw.cljs

@@ -59,25 +59,23 @@
         repo (state/get-current-repo)]
         repo (state/get-current-repo)]
     (when repo
     (when repo
       (let [repo-dir (util/get-repo-dir repo)]
       (let [repo-dir (util/get-repo-dir repo)]
-        (p/let [_ (create-draws-directory! repo)]
-          (util/p-handle
+        (->
+         (p/do!
+           (create-draws-directory! repo)
            (fs/write-file repo-dir path data)
            (fs/write-file repo-dir path data)
-           (fn [_]
-             (util/p-handle
-              (git-handler/git-add repo path)
-              (fn [_]
-                (ok-handler file)
-                (let [modified-at (tc/to-long (t/now))]
-                  (db/transact! repo
-                                [{:file/path path
-                                  :file/last-modified-at modified-at}
-                                 {:page/name file
-                                  :page/file path
-                                  :page/last-modified-at (tc/to-long (t/now))
-                                  :page/journal? false}])))))
-           (fn [error]
-             (prn "Write file failed, path: " path ", data: " data)
-             (js/console.dir error))))))))
+           (git-handler/git-add repo path)
+           (ok-handler file)
+           (let [modified-at (tc/to-long (t/now))]
+             (db/transact! repo
+                           [{:file/path path
+                             :file/last-modified-at modified-at}
+                            {:page/name file
+                             :page/file path
+                             :page/last-modified-at (tc/to-long (t/now))
+                             :page/journal? false}])))
+         (p/catch (fn [error]
+                    (prn "Write file failed, path: " path ", data: " data)
+                    (js/console.dir error))))))))
 
 
 (defn get-all-excalidraw-files
 (defn get-all-excalidraw-files
   [ok-handler]
   [ok-handler]