浏览代码

feat: rtc delete graph

Tienson Qin 1 年之前
父节点
当前提交
a47bc18f1a
共有 3 个文件被更改,包括 41 次插入20 次删除
  1. 15 8
      src/main/frontend/components/repo.cljs
  2. 18 6
      src/main/frontend/handler/db_based/rtc.cljs
  3. 8 6
      src/main/frontend/state.cljs

+ 15 - 8
src/main/frontend/components/repo.cljs

@@ -82,11 +82,15 @@
                                                              (state/pub-event! [:graph/unlinked repo current-repo])))
                                      action-confirm-fn (if only-cloud?
                                                          (fn []
-                                                           (state/set-state! [:file-sync/remote-graphs :loading] true)
-                                                           (go (<! (file-sync/<delete-graph GraphUUID))
-                                                               (state/delete-repo! repo)
-                                                               (state/delete-remote-graph! repo)
-                                                               (state/set-state! [:file-sync/remote-graphs :loading] false)))
+                                                           (let [current-repo (state/get-current-repo)
+                                                                 delete-graph (if (config/db-based-graph? current-repo)
+                                                                                rtc-handler/<rtc-delete-graph!
+                                                                                file-sync/<delete-graph)]
+                                                             (state/set-state! [:file-sync/remote-graphs :loading] true)
+                                                             (go (<! (delete-graph GraphUUID))
+                                                                 (state/delete-repo! repo)
+                                                                 (state/delete-remote-graph! repo)
+                                                                 (state/set-state! [:file-sync/remote-graphs :loading] false))))
                                                          unlink-or-remote-fn)
                                      confirm-fn
                                      (fn []
@@ -109,7 +113,9 @@
   (let [login? (boolean (state/sub :auth/id-token))
         repos (state/sub [:me :repos])
         repos (util/distinct-by :url repos)
-        remotes (state/sub [:file-sync/remote-graphs :graphs])
+        remotes (concat
+                 (state/sub :rtc/graphs)
+                 (state/sub [:file-sync/remote-graphs :graphs]))
         remotes-loading? (state/sub [:file-sync/remote-graphs :loading])
         repos (if (and login? (seq remotes))
                 (repo-handler/combine-local-&-remote-graphs repos remotes) repos)
@@ -134,7 +140,6 @@
               (t :open-a-directory)
               :on-click #(state/pub-event! [:graph/setup-a-repo]))])]]
 
-        ;; TODO: support rtc
         (when (and (file-sync/enable-sync?) login?)
           [:div
            [:hr]
@@ -146,7 +151,9 @@
                (when remotes-loading? [:small.pl-2 (ui/loading nil)])]
               :background "gray"
               :disabled remotes-loading?
-              :on-click #(file-sync/load-session-graphs))]]
+              :on-click (fn []
+                          (file-sync/load-session-graphs)
+                          (when config/dev? (rtc-handler/<get-remote-graphs))))]]
            (repos-inner remote-graphs)])]]
       (widgets/add-graph))))
 

+ 18 - 6
src/main/frontend/handler/db_based/rtc.cljs

@@ -13,6 +13,13 @@
      (let [token (state/get-auth-id-token)]
        (.rtc-upload-graph worker repo token "TODO:remote-graph-name")))))
 
+(defn <rtc-delete-graph!
+  [graph-uuid]
+  (when-let [^js worker @state/*db-worker]
+    (user-handler/<wrap-ensure-id&access-token
+     (let [token (state/get-auth-id-token)]
+       (.rtc-delete-graph worker token graph-uuid)))))
+
 (defn <rtc-download-graph!
   [repo graph-uuid]
   (when-let [^js worker @state/*db-worker]
@@ -38,10 +45,15 @@
            token (state/get-auth-id-token)]
        (p/let [result (.rtc-get-graphs worker repo token)
                graphs (bean/->clj result)
-               result (mapv (fn [graph]
-                              {:GraphName (:graph-name graph)
-                               :GraphUUID (:graph-uuid graph)
-                               :group (:group graph)
-                               :rtc-graph? true})
-                            graphs)]
+               result (->> graphs
+                           (remove (fn [graph]
+                                     (= (:graph-status graph) "deleting")))
+                           (mapv (fn [graph]
+                                   (merge
+                                    {:GraphName (or (:graph-name graph)
+                                                   ;; FIXME: remove this later
+                                                    (str (:graph-uuid graph)))
+                                     :GraphUUID (:graph-uuid graph)
+                                     :rtc-graph? true}
+                                    (dissoc graph :graph-uuid :graph-name)))))]
          (state/set-state! :rtc/graphs result))))))

+ 8 - 6
src/main/frontend/state.cljs

@@ -897,12 +897,14 @@ Similar to re-frame subscriptions"
 
 (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))))
+  (let [remove-repo! (fn [repos]
+                       (remove #(and
+                                 (:GraphUUID repo)
+                                 (:GraphUUID %)
+                                 (= (:GraphUUID repo) (:GraphUUID %))) repos))]
+    (if (:rtc-graph? repo)
+      (swap! state update :rtc/graphs remove-repo!)
+      (swap! state update-in [:file-sync/remote-graphs :graphs] remove-repo!))))
 
 (defn add-remote-graph!
   [repo]