Sfoglia il codice sorgente

enhance(ui): refactor the classic select modal with the shui dialog

charlie 1 anno fa
parent
commit
669299dd7a

+ 0 - 1
src/main/frontend/components/container.cljs

@@ -966,7 +966,6 @@
       (shui-dialog/install-modals)
       (shui-popup/install-popups)
 
-      (select/select-modal)
       (custom-context-menu)
       (plugins/custom-js-installer
        {:t t

+ 5 - 6
src/main/frontend/components/select.cljs

@@ -59,7 +59,7 @@
                        (reset! (::selected-choices new-state) choices))
                      new-state))
    :will-unmount (fn [state]
-                   (state/set-state! [:ui/open-select] nil)
+                   (shui/dialog-close! :ls-select-modal)
                    state)}
   [state {:keys [items limit on-chosen empty-placeholder
                  prompt-key input-default-placeholder close-modal?
@@ -234,9 +234,9 @@
                                :original-graph original-graph})))))
     :on-chosen #(dev-common-handler/import-chosen-graph (:graph %))}})
 
-(rum/defc select-modal < rum/reactive
-  []
-  (when-let [select-type (state/sub [:ui/open-select])]
+(defn dialog-select!
+  [select-type]
+  (when select-type
     (let [select-type-config (get (select-config) select-type)
           on-chosen' (:on-chosen select-type-config)]
       (shui/dialog-open!
@@ -249,5 +249,4 @@
        {:id :ls-select-modal
         :close-btn?  false
         :align :top
-        :content-props {:class "ls-dialog-select"}}))
-    nil))
+        :content-props {:class "ls-dialog-select"}}))))

+ 1 - 1
src/main/frontend/handler/common/developer.cljs

@@ -95,4 +95,4 @@
     (state/pub-event! [:graph/switch repo])))
 
 (defn ^:export replace-graph-with-db-file []
-  (state/set-state! :ui/open-select :db-graph-replace))
+  (state/pub-event! [:dialog-select/db-graph-replace]))

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

@@ -14,6 +14,7 @@
             [frontend.components.block :as block]
             [frontend.components.settings :as settings]
             [frontend.components.diff :as diff]
+            [frontend.components.select :as select]
             [frontend.components.encryption :as encryption]
             [frontend.components.file-sync :as file-sync]
             [frontend.components.git :as git-component]
@@ -784,6 +785,15 @@
     :title [:h2 "Create a new graph"]
     :style {:max-width "500px"}}))
 
+(defmethod handle :dialog-select/graph-open []
+  (select/dialog-select! :graph-open))
+
+(defmethod handle :dialog-select/graph-remove []
+  (select/dialog-select! :graph-remove))
+
+(defmethod handle :dialog-select/db-graph-replace []
+  (select/dialog-select! :db-graph-replace))
+
 (defmethod handle :graph/save-db-to-disk [[_ _opts]]
   (persist-db/export-current-graph! {:succ-notification? true}))
 

+ 2 - 2
src/main/frontend/modules/shortcut/config.cljs

@@ -444,12 +444,12 @@
 
    :graph/open                              {:fn      #(do
                                                          (editor-handler/escape-editing)
-                                                         (state/set-state! :ui/open-select :graph-open))
+                                                         (state/pub-event! [:dialog-select/graph-open]))
                                              :binding "alt+shift+g"}
 
    :graph/remove                            {:fn      #(do
                                                          (editor-handler/escape-editing)
-                                                         (state/set-state! :ui/open-select :graph-remove))
+                                                         (state/pub-event! [:dialog-select/graph-remove]))
                                              :binding []}
 
    :graph/add                               {:fn      (fn [] (route-handler/redirect! {:to :graphs}))

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

@@ -1621,8 +1621,7 @@ Similar to re-frame subscriptions"
              :modal/show? false
              :modal/fullscreen? false
              :modal/panel-content nil
-             :modal/dropdowns {}
-             :ui/open-select nil))))
+             :modal/dropdowns {}))))
 
 (defn get-reactive-custom-queries-chan
   []