瀏覽代碼

move *unstable-network to state

rcmerci 3 年之前
父節點
當前提交
bc55560a54

+ 1 - 3
src/main/frontend/components/file_sync.cljs

@@ -36,11 +36,9 @@
 (declare open-icloud-graph-clone-picker)
 
 
-(def *unstable-network (atom false))
-
 (rum/defc unstable-network < rum/reactive
   []
-  (let [unstable-network (rum/react *unstable-network)]
+  (let [unstable-network (state/sub :network/unstable?)]
     (when unstable-network
       [:div.text-sm "unstable network"])))
 

+ 2 - 2
src/main/frontend/fs/sync.cljs

@@ -289,8 +289,8 @@
        :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]))
+           (state/pub-event! [:network/unstable true])
+           (state/pub-event! [:network/unstable false]))
          (if (and
               (= 401 (get-in resp [:resp :status]))
               (= "Unauthorized" (:message (get-json-body (get-in resp [:resp :body])))))

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

@@ -889,8 +889,8 @@
                        [: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?)))
+(defmethod handle :network/unstable [[_ value]]
+  (state/set-network-unstable! value))
 
 
 (defn run!

+ 5 - 0
src/main/frontend/state.cljs

@@ -41,6 +41,7 @@
      :instrument/disabled?                  (storage/get "instrument-disabled")
      ;; TODO: how to detect the network reliably?
      :network/online?         true
+     :network/unstable?       false
      :indexeddb/support?      true
      :me                      nil
      :git/current-repo        current-graph
@@ -1427,6 +1428,10 @@ Similar to re-frame subscriptions"
   [value]
   (set-state! :network/online? value))
 
+(defn set-network-unstable!
+  [value]
+  (set-state! :network/unstable? value))
+
 (defn get-plugins-commands
   []
   (mapcat seq (flatten (vals (:plugin/installed-slash-commands @state)))))