瀏覽代碼

fix: persist other window's db on opening new window in another graph

Junyi Du 3 年之前
父節點
當前提交
9e150961d7
共有 3 個文件被更改,包括 38 次插入34 次删除
  1. 3 2
      src/main/electron/listener.cljs
  2. 19 16
      src/main/frontend/handler/events.cljs
  3. 16 16
      src/main/frontend/ui.cljs

+ 3 - 2
src/main/electron/listener.cljs

@@ -84,8 +84,9 @@
                              after-f #(ipc/ipc "persistGraphDone" repo)
                              error-f (fn []
                                        (after-f)
-                                       (notification/show! (t :graph/persist-error)
-                                                           :error))
+                                       (notification/show!
+                                        (t :graph/persist-error)
+                                        :error))
                              handlers {:before     before-f
                                        :on-success after-f
                                        :on-error   error-f}]

+ 19 - 16
src/main/frontend/handler/events.cljs

@@ -93,13 +93,20 @@
   (srs/update-cards-due-count!)
   (state/pub-event! [:graph/ready graph]))
 
-(defn- graph-switch-on-persisted 
+(def persist-db-noti-m
+  {:before     #(notification/show!
+                 (ui/loading (t :graph/persist))
+                 :warning)
+   :on-error   #(notification/show!
+                 (t :graph/persist-error)
+                 :error)})
+
+(defn- graph-switch-on-persisted
   "Logic for keeping db sync when switching graphs
    Only works for electron"
   [graph]
-  (p/let [;; save current db
-          _ (repo-handler/persist-db!)
-          ;; ask other windows to persist the targeting db
+  (p/let [current-repo (state/get-current-repo) 
+          _ (repo-handler/persist-db! current-repo persist-db-noti-m)
           _ (repo-handler/persist-otherwindow-db! graph)
           _ (repo-handler/restore-and-setup-repo! graph)]
     (graph-switch graph)))
@@ -113,6 +120,14 @@
      "Please wait seconds until all changes are saved for the current graph."
      :warning)))
 
+(defmethod handle :graph/open-new-window [[_ repo]]
+  (p/let [current-repo (state/get-current-repo)
+          target-repo (or repo current-repo)
+          _ (repo-handler/persist-db! current-repo persist-db-noti-m)
+          _ (when-not (= current-repo target-repo)
+              (repo-handler/persist-otherwindow-db! repo))]
+    (ui-handler/open-new-window! _ repo)))
+
 (defmethod handle :graph/migrated [[_ _repo]]
   (js/alert "Graph migrated."))
 
@@ -334,18 +349,6 @@
            :path
            js/decodeURI)))
 
-(defmethod handle :graph/open-new-window [[_ repo]]
-   ;; persistent current db, then open new window
-  (let [cur-repo (state/get-current-repo)]
-    (repo-handler/persist-db! cur-repo
-                              {:before     #(notification/show!
-                                             (ui/loading (t :graph/persist))
-                                             :warning)
-                               :on-success #(ui-handler/open-new-window! _ repo)
-                               :on-error   #(notification/show!
-                                             (t :graph/persist-error)
-                                             :error)})))
-
 (defn run!
   []
   (let [chan (state/get-events-chan)]

+ 16 - 16
src/main/frontend/ui.cljs

@@ -199,7 +199,7 @@
        {:style
         (when (or (= state "exiting")
                   (= state "exited"))
-                  {:z-index -1})}
+          {:z-index -1})}
        [:div.max-w-sm.w-full.shadow-lg.rounded-lg.pointer-events-auto.notification-area
         {:class (case state
                   "entering" "transition ease-out duration-300 transform opacity-0 translate-y-2 sm:translate-x-0"
@@ -215,7 +215,7 @@
             svg]
            [:div.ml-3.w-0.flex-1
             [:div.text-sm.leading-5.font-medium.whitespace-pre-line {:style {:margin 0}
-                                                 :class color-class}
+                                                                     :class color-class}
              content]]
            [:div.ml-4.flex-shrink-0.flex
             [:button.inline-flex.text-gray-400.focus:outline-none.focus:text-gray-500.transition.ease-in-out.duration-150
@@ -398,7 +398,7 @@
   (mixins/event-mixin attach-listeners)
   "Render an infinite list."
   [state _list-element-id body {:keys [on-load has-more more more-class]
-                               :or {more-class "text-sm"}}]
+                                :or {more-class "text-sm"}}]
   [:div
    body
    (when has-more
@@ -632,13 +632,13 @@
          {:style {:z-index (if show? (+ 999 idx) -1)}
           :label label}
          (css-transition
-           {:in show? :timeout 0}
-           (fn [state]
-             (modal-overlay state close-fn)))
+          {:in show? :timeout 0}
+          (fn [state]
+            (modal-overlay state close-fn)))
          (css-transition
-           {:in show? :timeout 0}
-           (fn [state]
-             (modal-panel show? modal-panel-content state close-fn false close-btn?)))]))))
+          {:in show? :timeout 0}
+          (fn [state]
+            (modal-panel show? modal-panel-content state close-fn false close-btn?)))]))))
 
 (defn loading
   [content]
@@ -678,9 +678,9 @@
         (when-not (mobile-util/is-native-platform?)
           [:a.block-control.opacity-50.hover:opacity-100.mr-2
            (cond->
-               {:style    {:width       14
-                           :height      16
-                           :margin-left -30}}
+            {:style    {:width       14
+                        :height      16
+                        :margin-left -30}}
              (not title-trigger?)
              (assoc :on-mouse-down on-mouse-down))
            [:span {:class (if @control? "control-show cursor-pointer" "control-hide")}
@@ -782,10 +782,10 @@
                 value (.-value target)]
 
             (on-change
-              (into []
-                (if checked?
-                  (conj checked-vals value)
-                  (disj checked-vals value))))))]
+             (into []
+                   (if checked?
+                     (conj checked-vals value)
+                     (disj checked-vals value))))))]
 
     [:div.ui__checkbox-list
      {:class class}