Sfoglia il codice sorgente

fix: remove ugly setTimeout

Tienson Qin 1 anno fa
parent
commit
dbbd5cf400

+ 2 - 2
src/main/frontend/components/imports.cljs

@@ -38,9 +38,9 @@
 
 (defn- finished-cb
   []
-  (route-handler/redirect-to-home!)
   (notification/show! "Import finished!" :success)
-  (js/setTimeout ui-handler/re-render-root! 100))
+  (ui-handler/re-render-root!)
+  (route-handler/redirect-to-home!))
 
 (defn- roam-import-handler
   [e]

+ 14 - 14
src/main/frontend/handler/import.cljs

@@ -229,20 +229,20 @@
 (defn import-from-sqlite-db!
   [buffer bare-graph-name finished-ok-handler]
   (let [graph (str config/db-version-prefix bare-graph-name)]
-    (-> (p/let [_ (persist-db/<import-db graph buffer)]
-          (state/add-repo! {:url graph})
-          (repo-handler/restore-and-setup-repo! graph))
-        (p/then
-         (fn [_result]
-           (state/set-current-repo! graph)
-           (persist-db/<export-db graph {})
-           (finished-ok-handler)))
-        (p/catch
-         (fn [e]
-           (js/console.error e)
-           (notification/show!
-            (str (.-message e))
-            :error))))))
+    (->
+     (p/do!
+      (persist-db/<import-db graph buffer)
+      (state/add-repo! {:url graph})
+      (repo-handler/restore-and-setup-repo! graph)
+      (state/set-current-repo! graph)
+      (persist-db/<export-db graph {})
+      (finished-ok-handler))
+     (p/catch
+      (fn [e]
+        (js/console.error e)
+        (notification/show!
+         (str (.-message e))
+         :error))))))
 
 (defn import-from-edn!
   [raw finished-ok-handler]

+ 2 - 1
src/main/frontend/handler/repo.cljs

@@ -198,7 +198,8 @@
           ;; TODO: handle global graph
            _ (state/pub-event! [:init/commands])
            _ (when-not file-graph-import? (state/pub-event! [:page/create (date/today) {:redirect? false}]))]
-     (js/setTimeout ui-handler/re-render-root! 100)
+     (route-handler/redirect-to-home!)
+     (ui-handler/re-render-root!)
      (graph-handler/settle-metadata-to-local! {:created-at (js/Date.now)})
      (prn "New db created: " full-graph-name)
      full-graph-name)