浏览代码

fix: second settings can't be opened

close #2254
Tienson Qin 4 年之前
父节点
当前提交
186a4c8b27

+ 1 - 1
src/main/frontend/components/header.cljs

@@ -106,7 +106,7 @@
           :icon svg/calendar-sm})
 
        {:title (t :settings)
-        :options {:on-click #(ui-handler/toggle-settings-modal!)}
+        :options {:on-click state/open-settings!}
         :icon svg/settings-sm}
 
        (when developer-mode?

+ 11 - 16
src/main/frontend/components/sidebar.cljs

@@ -267,20 +267,16 @@
                     (state/sidebar-add-block! (state/get-current-repo) "help" :help nil))}
        "?"])))
 
-(rum/defc settings-modal
-  [settings-open?]
-  (rum/use-effect!
-   (fn []
-     (if settings-open?
-       (state/set-modal!
-        (fn [close-fn]
-          (gobj/set close-fn "user-close" #(ui-handler/toggle-settings-modal!))
-          [:div.settings-modal (settings/settings)]))
-       (state/set-modal! nil))
-
-     (util/lock-global-scroll settings-open?)
-     #())
-   [settings-open?]) nil)
+(rum/defc settings-modal < rum/reactive
+  []
+  (let [settings-open? (state/sub :ui/settings-open?)]
+    (if settings-open?
+      (do
+        (state/set-modal!
+         (fn [] [:div.settings-modal (settings/settings)]))
+        (util/lock-global-scroll settings-open?))
+      (state/set-modal! nil))
+    nil))
 
 (rum/defcs sidebar <
   (mixins/modal :modal/show?)
@@ -303,7 +299,6 @@
         theme (state/sub :ui/theme)
         system-theme? (state/sub :ui/system-theme?)
         white? (= "white" (state/sub :ui/theme))
-        settings-open? (state/sub :ui/settings-open?)
         sidebar-open?  (state/sub :ui/sidebar-open?)
         route-name (get-in route-match [:data :name])
         global-graph-pages? (= :graph route-name)
@@ -359,7 +354,7 @@
 
         (ui/notification)
         (ui/modal)
-        (settings-modal settings-open?)
+        (settings-modal)
         (custom-context-menu)
         [:a#download.hidden]
         (when

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

@@ -1235,6 +1235,14 @@
   []
   (toggle! :ui/settings-open?))
 
+(defn close-settings!
+  []
+  (set-state! :ui/settings-open? false))
+
+(defn open-settings!
+  []
+  (set-state! :ui/settings-open? true))
+
 ;; TODO: Move those to the uni `state`
 
 (defonce editor-op (atom nil))

+ 4 - 5
src/main/frontend/ui.cljs

@@ -385,9 +385,6 @@
       {:class       (if on? (if small? "translate-x-4" "translate-x-5") "translate-x-0")
        :aria-hidden "true"}]]]))
 
-(defn apply-close-fn [close-fn]
-  (fn [] (apply (or (gobj/get close-fn "user-close") close-fn) [])))
-
 (defonce modal-show? (atom false))
 (rum/defc modal-overlay
   [state close-fn]
@@ -397,7 +394,7 @@
              "entered" "ease-out duration-300 opacity-100"
              "exiting" "ease-in duration-200 opacity-100"
              "exited" "ease-in duration-200 opacity-0")
-    :on-click (apply-close-fn close-fn)}
+    :on-click close-fn}
    [:div.absolute.inset-0.opacity-75]])
 
 (rum/defc modal-panel
@@ -445,7 +442,9 @@
   (let [modal-panel-content (state/sub :modal/panel-content)
         fullscreen? (state/sub :modal/fullscreen?)
         show? (boolean modal-panel-content)
-        close-fn #(state/close-modal!)
+        close-fn (fn []
+                   (state/close-modal!)
+                   (state/close-settings!))
         modal-panel-content (or modal-panel-content (fn [close] [:div]))]
     [:div.ui__modal
      {:style {:z-index (if show? 10 -1)}}