diff --git a/src/main/frontend/components/file_sync.cljs b/src/main/frontend/components/file_sync.cljs index a59dc07094..408746b202 100644 --- a/src/main/frontend/components/file_sync.cljs +++ b/src/main/frontend/components/file_sync.cljs @@ -135,7 +135,9 @@ (when-let [GraphUUID (get (async/= latest-txid 0)]} (-> (p/let [_ (persist-var/-reset-value! graphs-txid [user-uuid graph-uuid latest-txid] repo) _ (persist-var/persist-save graphs-txid)] - (state/pub-event! [:graph/refresh]) (when (state/developer-mode?) (assert-local-txid<=remote-txid))) p->c)) diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index ff09f8f2c6..b104650ed7 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -113,16 +113,12 @@ (route-handler/redirect-to-home!))) (when-let [dir-name (config/get-repo-dir repo)] (fs/watch-dir! dir-name)) - (repo-handler/refresh-repos!) (file-sync-restart!)) (defmethod handle :graph/unlinked [repo current-repo] (when (= (:url repo) current-repo) (file-sync-restart!))) -(defmethod handle :graph/refresh [_] - (repo-handler/refresh-repos!)) - ;; FIXME: awful multi-arty function. ;; Should use a `-impl` function instead of the awful `skip-ios-check?` param with nested callback. (defn- graph-switch @@ -141,7 +137,6 @@ (fs/watch-dir! dir-name)) (srs/update-cards-due-count!) (state/pub-event! [:graph/ready graph]) - (repo-handler/refresh-repos!) (file-sync-restart!))))) ;; Parameters for the `persist-db` function, to show the notification messages diff --git a/src/main/frontend/handler/file_sync.cljs b/src/main/frontend/handler/file_sync.cljs index c48ea6f5c5..90493e56e0 100644 --- a/src/main/frontend/handler/file_sync.cljs +++ b/src/main/frontend/handler/file_sync.cljs @@ -49,7 +49,8 @@ (string? r)) (let [tx-info [0 r (user/user-uuid) (state/get-current-repo)]] (> remote-repos (map #(assoc % :remote? true)))))] (let [repos' (group-by :GraphUUID repos') @@ -515,7 +515,7 @@ [url] (when-let [graphs (seq (and url (combine-local-&-remote-graphs (state/get-repos) - (state/get-remote-repos))))] + (state/get-remote-graphs))))] (first (filter #(when-let [url' (:url %)] (= url url')) graphs)))) @@ -524,7 +524,7 @@ (p/let [repos (get-repos) repos' (combine-local-&-remote-graphs repos - (state/get-remote-repos))] + (state/get-remote-graphs))] (state/set-repos! repos') repos')) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 559ac957d1..9694236e4a 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -711,7 +711,7 @@ Similar to re-frame subscriptions" (when-not (mobile-util/native-platform?) "local"))) -(defn get-remote-repos +(defn get-remote-graphs [] (get-in @state [:file-sync/remote-graphs :graphs])) @@ -720,6 +720,22 @@ Similar to re-frame subscriptions" (when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))] (some #(when (= (:GraphUUID %) (str uuid)) %) graphs))) +(defn delete-remote-graph! + [repo] + (swap! state update-in [:file-sync/remote-graphs :graphs] + (fn [repos] + (remove #(and + (:GraphUUID repo) + (:GraphUUID %) + (= (:GraphUUID repo) (:GraphUUID %))) repos)))) + +(defn add-remote-graph! + [repo] + (swap! state update-in [:file-sync/remote-graphs :graphs] + (fn [repos] + (->> (conj repos repo) + (distinct))))) + (defn get-repos [] (get-in @state [:me :repos]))