瀏覽代碼

enhance(sync): add simple notification for unstable network

rcmerci 2 年之前
父節點
當前提交
e5ec1da9fd

+ 9 - 0
src/main/frontend/components/file_sync.cljs

@@ -35,6 +35,15 @@
 (declare maybe-onboarding-show)
 (declare open-icloud-graph-clone-picker)
 
+
+(def *unstable-network (atom false))
+
+(rum/defc unstable-network < rum/reactive
+  []
+  (let [unstable-network (rum/react *unstable-network)]
+    (when unstable-network
+      [:div.text-sm "unstable network"])))
+
 (rum/defc clone-local-icloud-graph-panel
   [repo graph-name close-fn]
 

+ 1 - 0
src/main/frontend/components/header.cljs

@@ -197,6 +197,7 @@
              (ui/icon "chevron-left" {:size 26})])))]
 
      [:div.r.flex.drag-region
+      (fs-sync/unstable-network)
       (when (and current-repo
                  (not (config/demo-graph? current-repo))
                  (user-handler/alpha-or-beta-user?))

+ 3 - 0
src/main/frontend/fs/sync.cljs

@@ -288,6 +288,9 @@
      (if (and *stop @*stop (contains? stoppable-apis api-name))
        :stop
        (let [resp (<! (<request-once api-name body token))]
+         (if (= 0 (get-in resp [:resp :status]))
+           (state/pub-event! [:network/unstable false])
+           (state/pub-event! [:network/unstable true]))
          (if (and
               (= 401 (get-in resp [:resp :status]))
               (= "Unauthorized" (:message (get-json-body (get-in resp [:resp :body])))))

+ 5 - 1
src/main/frontend/handler/events.cljs

@@ -119,7 +119,7 @@
     (fs/watch-dir! dir-name))
   (file-sync-restart!))
 
-(defmethod handle :graph/unlinked [repo current-repo]
+(defmethod handle :graph/unlinked [[repo current-repo]]
   (when (= (:url repo) current-repo)
     (file-sync-restart!)))
 
@@ -889,6 +889,10 @@
                        [:p "Don't forget to re-index your graph when all the conflicts are resolved."]]
                       :status :error}]))
 
+(defmethod handle :network/unstable [[_ recover?]]
+  (reset! file-sync/*unstable-network (not recover?)))
+
+
 (defn run!
   []
   (let [chan (state/get-events-chan)]