Browse Source

feat(mobile): quick add

Tienson Qin 5 months ago
parent
commit
f2bf7e36ef

+ 9 - 2
src/main/frontend/components/block.cljs

@@ -93,6 +93,7 @@
             [logseq.shui.hooks :as hooks]
             [logseq.shui.ui :as shui]
             [medley.core :as medley]
+            [mobile.state :as mobile-state]
             [promesa.core :as p]
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
@@ -3657,7 +3658,10 @@
                    (when original-block " embed-block"))
        :haschild (str (boolean has-child?))
        :on-touch-start (fn [event uuid]
-                         (when-not (or @*dragging? (state/editing?))
+                         (when-not (or @*dragging?
+                                       (state/editing?)
+                                       (contains? #{:ls-quick-add}
+                                                  (get-in @mobile-state/*popup-data [:opts :id])))
                            (block-handler/on-touch-start event uuid)))
        :on-touch-end (fn [event]
                        (when-not @*dragging?
@@ -4391,7 +4395,10 @@
 (rum/defc block-list
   [config blocks]
   (let [[virtualized? _] (rum/use-state (not (or (and (:journals? config) (< (count blocks) 50))
-                                                 (:block-children? config))))
+                                                 (:block-children? config)
+                                                 (and (util/mobile?)
+                                                      (= common-config/quick-add-page-name
+                                                         (:block/title (:block/page (first blocks))))))))
         render-item (fn [idx]
                       (let [top? (zero? idx)
                             bottom? (= (dec (count blocks)) idx)

+ 19 - 14
src/main/frontend/components/quick_add.cljs

@@ -5,6 +5,7 @@
             [frontend.db :as db]
             [frontend.handler.editor :as editor-handler]
             [frontend.state :as state]
+            [frontend.util :as util]
             [logseq.common.config :as common-config]
             [logseq.db :as ldb]
             [logseq.shui.ui :as shui]
@@ -21,17 +22,21 @@
   []
   (when (db/get-page (date/today))
     (when-let [add-page (ldb/get-built-in-page (db/get-db) common-config/quick-add-page-name)]
-      [:div.ls-quick-capture.flex.flex-1.flex-col.w-full.gap-4
-       [:div.font-medium.text-xl.border-b.pb-4
-        "Quick add"]
-       [:div.block.-ml-6.content
-        (page/page-blocks-cp add-page {})]
-       [:div.flex.flex-row.gap-2.items-center
-        [:div
-         (shui/button
-          {:variant :outline
-           :size :sm
-           :on-click (fn [_e]
-                       (editor-handler/quick-add-blocks!))}
-          (shui/shortcut ["mod" "e"])
-          "Add to today")]]])))
+      (let [mobile? (util/mobile?)]
+        [:div.ls-quick-capture.flex.flex-1.flex-col.w-full.gap-4
+         [:div.font-medium.border-b.pb-4
+          {:class (when-not mobile? "text-xs")}
+          "Quick add"]
+         [:div.content
+          {:class (if mobile?
+                    "flex flex-1 flex-col w-full"
+                    "block -ml-6")}
+          (page/page-blocks-cp add-page {})]
+         [:div
+          (shui/button
+           {:variant (if mobile? :default :outline)
+            :size :sm
+            :on-click (fn [_e]
+                        (editor-handler/quick-add-blocks!))}
+           (when-not mobile? (shui/shortcut ["mod" "e"]))
+           "Add to today")]]))))

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

@@ -71,6 +71,7 @@
             [logseq.outliner.property :as outliner-property]
             [logseq.shui.dialog.core :as shui-dialog]
             [logseq.shui.popup.core :as shui-popup]
+            [mobile.state :as mobile-state]
             [promesa.core :as p]
             [rum.core :as rum]))
 
@@ -3942,7 +3943,9 @@
            (edit-block! block :max {:container-id :unknown-container}))
          (api-insert-new-block! "" {:page (:block/uuid add-page)
                                     :container-id :unknown-container})))
-     (state/pub-event! [:dialog/quick-add]))))
+     (state/pub-event! [(if (util/mobile?)
+                          :dialog/mobile-quick-add
+                          :dialog/quick-add)]))))
 
 (defn quick-add-blocks!
   []
@@ -3956,6 +3959,7 @@
              (move-blocks! children today-last-child true)
              (move-blocks! children today false)))
          (state/close-modal!)
+         (mobile-state/set-popup! nil)
          (when (seq children)
            (notification/show! "Blocks added to today!" :success)))))))
 

+ 8 - 0
src/main/mobile/components/app.cljs

@@ -8,6 +8,7 @@
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.db.conn :as db-conn]
+            [frontend.handler.editor :as editor-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.user :as user-handler]
@@ -15,6 +16,7 @@
             [frontend.rum :as frum]
             [frontend.state :as state]
             [frontend.ui :as ui]
+            [frontend.util :as util]
             [goog.date :as gdate]
             [logseq.db :as ldb]
             [logseq.shui.dialog.core :as shui-dialog]
@@ -81,6 +83,12 @@
    (ion/tab-button
     {:tab "search"}
     (ion/tabler-icon "search" {:size 22}) "Search")
+   (ion/tab-button
+    {:tab "quick-add"
+     :on-pointer-down (fn [e]
+                        (util/stop e)
+                        (editor-handler/show-quick-add))}
+    (ion/tabler-icon "plus" {:size 22}) "Quick add")
    (ion/tab-button
     {:tab "settings"}
     (ion/tabler-icon "settings" {:size 22}) "Settings")))

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

@@ -1,8 +1,10 @@
 (ns mobile.components.popup
   "Mobile popup"
   (:require [dommy.core :as dom]
+            [frontend.state :as state]
             [logseq.shui.popup.core :as shui-popup]
             [logseq.shui.ui :as shui]
+            [mobile.init :as init]
             [mobile.ionic :as ion]
             [mobile.state :as mobile-state]
             [rum.core :as rum]))
@@ -66,6 +68,9 @@
 (rum/defc popup < rum/reactive
   []
   (let [{:keys [open? content-fn opts]} (rum/react mobile-state/*popup-data)]
+    (when open?
+      ;; (state/clear-edit!)
+      (init/keyboard-hide))
     (ion/modal
      (merge
       {:isOpen (boolean open?)

+ 4 - 3
src/main/mobile/core.cljs

@@ -1,15 +1,16 @@
 (ns mobile.core
   "Mobile core"
   (:require ["react-dom/client" :as rdc]
-            [mobile.components.app :as app]
-            [mobile.init :as init]
-            [mobile.state :as state]
             [frontend.background-tasks]
             [frontend.components.page :as page]
             [frontend.handler :as fhandler]
             [frontend.handler.db-based.rtc-background-tasks]
             [frontend.handler.route :as route-handler]
             [frontend.util :as util]
+            [mobile.components.app :as app]
+            [mobile.events]
+            [mobile.init :as init]
+            [mobile.state :as state]
             [reitit.frontend :as rf]
             [reitit.frontend.easy :as rfe]))
 

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

@@ -1,7 +1,9 @@
 (ns mobile.events
   "Mobile events"
-  (:require [mobile.init :as init]
+  (:require [frontend.components.quick-add :as quick-add]
             [frontend.handler.events :as events]
+            [mobile.init :as init]
+            [mobile.state :as mobile-state]
             [promesa.core :as p]))
 
 ;; TODO: move more events here
@@ -9,3 +11,8 @@
   (p/do!
    (p/delay 1000)
    (init/mobile-post-init)))
+
+(defmethod events/handle :dialog/mobile-quick-add [_]
+  (mobile-state/set-popup! {:open? true
+                            :content-fn (fn [] (quick-add/quick-add))
+                            :opts {:id :ls-quick-add}}))