浏览代码

fix: adjust migration flow for github repos

Tienson Qin 4 年之前
父节点
当前提交
323f23f76a

+ 1 - 1
src/main/frontend/db/migrate.cljs

@@ -29,5 +29,5 @@
   [repo db]
   (prn "Migrate DB")
   (reset! debug-db db)
-  (state/pub-event! [:graph/added repo])
+  (state/pub-event! [:graph/migrated repo])
   (with-schema db db-schema/schema))

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

@@ -53,7 +53,8 @@
 
 (defn store-schema!
   []
-  (storage/set :db-schema db-schema/schema))
+  (storage/set :db-schema (assoc db-schema/schema
+                                 :db/version db-schema/version)))
 
 (defn- get-me-and-repos
   []

+ 7 - 0
src/main/frontend/handler/events.cljs

@@ -53,6 +53,13 @@
        (migrate/show-convert-notification! repo)))
    5000))
 
+(defmethod handle :graph/migrated [[_ repo]]
+  (js/setTimeout
+   (fn []
+     (when (not (:markdown/version (state/get-config)))
+       (migrate/show-migrated-notification! repo)))
+   5000))
+
 (defn get-local-repo
   []
   (when-let [repo (state/get-current-repo)]

+ 15 - 0
src/main/frontend/handler/export.cljs

@@ -14,6 +14,7 @@
             [frontend.handler.common :as common-handler]
             [frontend.extensions.zip :as zip]
             [frontend.modules.file.core :as outliner-file]
+            [frontend.handler.file :as file-handler]
             [frontend.modules.outliner.tree :as outliner-tree]
             [promesa.core :as p]))
 
@@ -156,6 +157,20 @@
           (.setAttribute anchor "download" (.-name zipfile))
           (.click anchor))))))
 
+(defn export-git-repo-as-zip!
+  [repo]
+  (p/let [files (file-handler/load-files repo)
+          contents (file-handler/load-multiple-files repo files)
+          files (zipmap files contents)
+          [owner repo-name] (util/get-git-owner-and-repo repo)
+          repo-name (str owner "-" repo-name)]
+    (when (seq files)
+      (p/let [zipfile (zip/make-zip repo-name files repo)]
+        (when-let [anchor (gdom/getElement "download")]
+          (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile))
+          (.setAttribute anchor "download" (.-name zipfile))
+          (.click anchor))))))
+
 (defn get-md-file-contents
   [repo]
   (let [conn (db/get-conn repo)]

+ 39 - 12
src/main/frontend/handler/migrate.cljs

@@ -5,9 +5,11 @@
             [frontend.handler.config :as config-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.web.nfs :as nfs-handler]
+            [frontend.handler.user :as user-handler]
             [frontend.ui :as ui]
             [frontend.state :as state]
-            [promesa.core :as p]))
+            [promesa.core :as p]
+            [clojure.string :as string]))
 
 (defn convert-md-files!
   [repo]
@@ -38,24 +40,49 @@
 
     [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."]
 
-    [:p.mt-2 "If you've converted this graph before, click on this button so that you won't see this notification again."]
-    (ui/button "Yes, it's already converted!"
-      :on-click (fn []
-                  (notification/clear-all!)
-                  (config-handler/set-config! :markdown/version 2)))
+    [:div
+     [:p.mt-2 "If you've converted this graph before, click on this button so that you won't see this notification again."]
+     (ui/button "Yes, it's already converted!"
+       :on-click (fn []
+                   (notification/clear-all!)
+                   (config-handler/set-config! :markdown/version 2)))]
+
     [:hr]
 
-    [:p "Otherwise, let's make a backup first."]
+    [:p "Let's make a backup first."]
     [:p
      (ui/button "Download this graph"
        :on-click (fn []
                    (export/export-repo-as-zip! repo)))]
 
-    [:b "Make sure you've downloaded this graph! Now let's convert the Markdown files."]
+    [:div
+     [:b "Make sure you've downloaded this graph! Now let's convert the Markdown files."]
+     [:p
+      (ui/button "Start to convert!"
+        :on-click (fn []
+                    (notification/clear-all!)
+                    (convert-md-files! repo)))]]]
+   :warning
+   false))
+
+(defn show-migrated-notification!
+  [repo]
+  (notification/show!
+   [:div
+    [:h1 (str "Graph: " repo)]
+
+    [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."]
+
+    [:hr]
+
+    [:p "1. Let's make a backup first."]
     [:p
-     (ui/button "Start to convert!"
-       :on-click (fn []
-                   (notification/clear-all!)
-                   (convert-md-files! repo)))]]
+     (ui/button "Download this graph"
+       :on-click (fn [] (export/export-git-repo-as-zip! repo)))]
+
+    [:div
+     [:p [:b "2. Make sure you've downloaded this graph! Now click this button to logout and login again."]]
+     (ui/button "Logout"
+       :on-click user-handler/sign-out!)]]
    :warning
    false))