Kaynağa Gözat

fix: open editor in quick add

Tienson Qin 6 ay önce
ebeveyn
işleme
e812f46f36

+ 1 - 3
src/main/frontend/handler/editor.cljs

@@ -3938,9 +3938,7 @@
     (p/do!
     (p/do!
      (db-async/<get-block graph (date/today))
      (db-async/<get-block graph (date/today))
      (p/let [add-page (db-async/<get-block graph (:db/id (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)))]
      (p/let [add-page (db-async/<get-block graph (:db/id (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)))]
-       (if (:block/_parent add-page)
-         (let [block (last (ldb/sort-by-order (:block/_parent add-page)))]
-           (edit-block! block :max {:container-id :unknown-container}))
+       (when-not (:block/_parent add-page)
          (api-insert-new-block! "" {:page (:block/uuid add-page)
          (api-insert-new-block! "" {:page (:block/uuid add-page)
                                     :container-id :unknown-container})))
                                     :container-id :unknown-container})))
      (state/pub-event! [(if (util/mobile?)
      (state/pub-event! [(if (util/mobile?)

+ 28 - 5
src/main/mobile/components/popup.cljs

@@ -1,9 +1,14 @@
 (ns mobile.components.popup
 (ns mobile.components.popup
   "Mobile popup"
   "Mobile popup"
   (:require [dommy.core :as dom]
   (:require [dommy.core :as dom]
+            [frontend.db :as db]
+            [frontend.handler.editor :as editor-handler]
             [frontend.state :as state]
             [frontend.state :as state]
+            [logseq.common.config :as common-config]
+            [logseq.db :as ldb]
             [logseq.shui.popup.core :as shui-popup]
             [logseq.shui.popup.core :as shui-popup]
             [logseq.shui.ui :as shui]
             [logseq.shui.ui :as shui]
+            [mobile.components.ui :as mobile-ui]
             [mobile.init :as init]
             [mobile.init :as init]
             [mobile.ionic :as ion]
             [mobile.ionic :as ion]
             [mobile.state :as mobile-state]
             [mobile.state :as mobile-state]
@@ -11,7 +16,7 @@
 
 
 (defonce *last-popup-modal? (atom nil))
 (defonce *last-popup-modal? (atom nil))
 
 
-(defn warp-calc-commands-popup-side
+(defn wrap-calc-commands-popup-side
   [pos opts]
   [pos opts]
   (let [[side mh] (let [[_x y _ height] pos
   (let [[side mh] (let [[_x y _ height] pos
                         vh js/window.innerHeight
                         vh js/window.innerHeight
@@ -29,7 +34,7 @@
   [event content-fn {:keys [id dropdown-menu?] :as opts}]
   [event content-fn {:keys [id dropdown-menu?] :as opts}]
   (cond
   (cond
     (and (keyword? id) (= "editor.commands" (namespace id)))
     (and (keyword? id) (= "editor.commands" (namespace id)))
-    (let [opts (warp-calc-commands-popup-side event opts)
+    (let [opts (wrap-calc-commands-popup-side event opts)
           side (some-> opts :content-props :side)
           side (some-> opts :content-props :side)
           max-h (some-> opts :max-popup-height (js/parseInt) (- 48))
           max-h (some-> opts :max-popup-height (js/parseInt) (- 48))
           _ (when max-h (js/document.documentElement.style.setProperty
           _ (when max-h (js/document.documentElement.style.setProperty
@@ -65,13 +70,30 @@
 (set! shui/popup-show! popup-show!)
 (set! shui/popup-show! popup-show!)
 (set! shui/popup-hide! popup-hide!)
 (set! shui/popup-hide! popup-hide!)
 
 
+(rum/defc inner-content <
+  {:will-unmount (fn [state]
+                   (state/clear-edit!)
+                   (init/keyboard-hide)
+                   state)}
+  [content-fn]
+  (content-fn))
+
 (rum/defc popup < rum/reactive
 (rum/defc popup < rum/reactive
   []
   []
   (let [{:keys [open? content-fn opts]} (rum/react mobile-state/*popup-data)
   (let [{:keys [open? content-fn opts]} (rum/react mobile-state/*popup-data)
         initial-breakpoint (if (= (:id opts) :ls-quick-add) 1 0.75)]
         initial-breakpoint (if (= (:id opts) :ls-quick-add) 1 0.75)]
     (when open?
     (when open?
-      (state/clear-edit!)
-      (init/keyboard-hide))
+      (if (= :ls-quick-add (:id opts))
+        (when-let [add-page (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)]
+          (when (:block/_parent add-page)
+            (js/setTimeout
+             (fn []
+               (let [block (last (ldb/sort-by-order (:block/_parent add-page)))]
+                 (editor-handler/edit-block! block :max {:container-id :unknown-container})))
+             500)))
+        (do
+          (state/clear-edit!)
+          (init/keyboard-hide))))
     (ion/modal
     (ion/modal
      (merge
      (merge
       {:isOpen (boolean open?)
       {:isOpen (boolean open?)
@@ -86,4 +108,5 @@
        (when-let [title (:title opts)]
        (when-let [title (:title opts)]
          [:h2.py-2.opacity-40 title])
          [:h2.py-2.opacity-40 title])
        (when content-fn
        (when content-fn
-         (content-fn))]))))
+         (mobile-ui/classic-app-container-wrap
+          (inner-content content-fn)))]))))

+ 1 - 3
src/main/mobile/events.cljs

@@ -2,7 +2,6 @@
   "Mobile events"
   "Mobile events"
   (:require [frontend.components.quick-add :as quick-add]
   (:require [frontend.components.quick-add :as quick-add]
             [frontend.handler.events :as events]
             [frontend.handler.events :as events]
-            [mobile.components.ui :as mobile-ui]
             [mobile.init :as init]
             [mobile.init :as init]
             [mobile.state :as mobile-state]
             [mobile.state :as mobile-state]
             [promesa.core :as p]))
             [promesa.core :as p]))
@@ -16,6 +15,5 @@
 (defmethod events/handle :dialog/mobile-quick-add [_]
 (defmethod events/handle :dialog/mobile-quick-add [_]
   (mobile-state/set-popup! {:open? true
   (mobile-state/set-popup! {:open? true
                             :content-fn (fn []
                             :content-fn (fn []
-                                          (mobile-ui/classic-app-container-wrap
-                                           (quick-add/quick-add)))
+                                          (quick-add/quick-add))
                             :opts {:id :ls-quick-add}}))
                             :opts {:id :ls-quick-add}}))