Browse Source

fix: sync status

Tienson Qin 3 years ago
parent
commit
c300d6bc02

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

@@ -323,12 +323,6 @@
             ]}))])))
 
 (rum/defc pick-local-graph-for-sync [graph]
-  (rum/use-effect!
-   (fn []
-     (file-sync-handler/set-wait-syncing-graph graph)
-     #(file-sync-handler/set-wait-syncing-graph nil))
-   [graph])
-
   [:div.cp__file-sync-related-normal-modal
    [:div.flex.justify-center.pb-4 [:span.icon-wrap (ui/icon "cloud-download")]]
 
@@ -354,8 +348,7 @@
                    (->
                     (page-handler/ls-dir-files!
                      (fn [{:keys [url]}]
-                       (file-sync-handler/init-remote-graph url)
-                       ;; TODO: wait for switch done
+                       (file-sync-handler/init-remote-graph url graph)
                        (js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200))
 
                      {:empty-dir?-or-pred

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

@@ -97,7 +97,8 @@
                                      (state/set-modal! (confirm-fn)))
                                    (do
                                      (repo-handler/remove-repo! repo)
-                                     (file-sync/load-session-graphs))))}
+                                     (file-sync/load-session-graphs)
+                                     (state/pub-event! [:graph/unlinked]))))}
                     (if only-cloud? "Remove" "Unlink")])])]]))
 
 (rum/defc repos < rum/reactive

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

@@ -2780,7 +2780,6 @@
     (go
       (when (and (graph-sync-off? repo) @network-online-cursor)
         (<! (p->c (persist-var/-load graphs-txid)))
-
         (let [[user-uuid graph-uuid txid] @graphs-txid]
           (when (and user-uuid graph-uuid txid
                      (user/logged-in?)

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

@@ -108,6 +108,10 @@
   (repo-handler/refresh-repos!)
   (file-sync-restart!))
 
+(defmethod handle :graph/unlinked [_]
+  (repo-handler/refresh-repos!)
+  (file-sync-restart!))
+
 (defmethod handle :graph/refresh [_]
   (repo-handler/refresh-repos!))
 

+ 3 - 10
src/main/frontend/handler/file_sync.cljs

@@ -93,8 +93,7 @@
   (let [repo (state/get-current-repo)
         user-uuid (user/user-uuid)]
     (sync/update-graphs-txid! 0 graph-uuid user-uuid repo)
-    (swap! refresh-file-sync-component not)
-    (state/pub-event! [:graph/switch repo {:persist? false}])))
+    (swap! refresh-file-sync-component not)))
 
 (defn download-version-file
   ([graph-uuid file-uuid version-uuid]
@@ -165,15 +164,9 @@
             all-version-list))))))
 
 
-(def *wait-syncing-graph (atom nil))
-
-(defn set-wait-syncing-graph
-  [graph]
-  (reset! *wait-syncing-graph graph))
-
 (defn init-remote-graph
-  [local]
-  (when-let [graph (and local @*wait-syncing-graph)]
+  [local graph]
+  (when (and local graph)
     (notification/show!
      (str "Start syncing the remote graph "
           (:GraphName graph)

+ 1 - 1
src/main/frontend/handler/web/nfs.cljs

@@ -188,7 +188,7 @@
                           (p/let [files (map #(dissoc % :file/file) result)
                                   graphs-txid-meta (util-fs/read-graphs-txid-info dir-name)
                                   graph-uuid (and (vector? graphs-txid-meta) (second graphs-txid-meta))]
-                            (if-let [exists-graph (state/get-sync-graph-by-uuid graph-uuid)]
+                            (if-let [exists-graph (state/get-sync-graph-by-id graph-uuid)]
                               (state/pub-event!
                                [:notification/show
                                 {:content (str "This graph already exists in \"" (:root exists-graph) "\"")

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

@@ -1788,10 +1788,13 @@ Similar to re-frame subscriptions"
               {:is-active? is-active?
                :timestamp (inst-ms (js/Date.))}))
 
-(defn get-sync-graph-by-uuid
+(defn get-sync-graph-by-id
   [graph-uuid]
   (when graph-uuid
-    (first (filter #(= graph-uuid (:GraphUUID %))(get-repos)))))
+    (let [graph (first (filter #(= graph-uuid (:GraphUUID %))
+                               (get-repos)))]
+      (when (:url graph)
+        graph))))
 
 (defn unlinked-dir?
   [dir]