Browse Source

enhance(capacitor): reactive journals

charlie 6 months ago
parent
commit
b9673171fd

+ 9 - 4
src/main/capacitor/app.cljs

@@ -9,6 +9,7 @@
             [capacitor.state :as state]
             [capacitor.handler :as handler]
             [capacitor.pages.utils :as pages-util]
+            [capacitor.components.ui :as ui]
             [frontend.db-mixins :as db-mixins]
             [frontend.state :as fstate]
             [logseq.db :as ldb]
@@ -28,7 +29,7 @@
   []
   (-> (react/q (fstate/get-current-repo)
         [:frontend.worker.react/journals]
-        {:async-query-fn
+        {:query-fn
          (fn []
            (p/let [{:keys [data]} (handler/<load-view-data nil {:journals? true})]
              (remove nil? data)))}
@@ -72,7 +73,7 @@
         (for [page all-pages]
           (let [ident (some-> (:block/tags page) first :db/ident)]
             [:li.font-mono.flex.items-center.py-1.active:opacity-50.active:underline.whitespace-nowrap
-             {:on-click #(pages-util/nav-to-block! page)}
+             {:on-click #(pages-util/nav-to-block! page {:reload-pages! (fn [] (set-reload! (inc reload)))})}
              (case ident
                :logseq.class/Property (ionic/tabler-icon "letter-t")
                :logseq.class/Page (ionic/tabler-icon "file")
@@ -154,5 +155,9 @@
       [(rum/deref nav-ref)])
 
     [:> (.-IonApp ionic/ionic-react)
-     (ionic/ion-nav {:ref nav-ref :root root
-                     :animated true :swipeGesture false})]))
+     [:<>
+      (ionic/ion-nav {:ref nav-ref :root root
+                      :animated true :swipeGesture false})
+
+      (ui/install-notifications)
+      ]]))

+ 25 - 6
src/main/capacitor/pages/blocks.cljs

@@ -5,6 +5,7 @@
             [frontend.db.async :as db-async]
             [frontend.db.utils :as db-utils]
             [frontend.handler.editor :as editor-handler]
+            [frontend.handler.page :as page-handler]
             [frontend.state :as fstate]
             [capacitor.ionic :as ionic]))
 
@@ -32,18 +33,30 @@
       (ionic/ion-header
         (ionic/ion-toolbar
           (ionic/ion-buttons {:slot "end"}
-            (ionic/ion-button {:on-click #(close!)} "Cancel"))
-
+            (when (not (nil? (:db/id block)))
+              (ionic/ion-button {:fill "clear"
+                                 :class "opacity-80 text-red-500"
+                                 :on-click (fn []
+                                             (-> (editor-handler/delete-block-aux! block)
+                                               (p/then (fn []
+                                                         (close!)
+                                                         (reload-page!)))))}
+                (ionic/tabler-icon "trash" {:size 26}))))
           (ionic/ion-title (or title "Untitled"))))
 
       (ionic/ion-content {:class "ion-padding"}
         [:div.py-2
          (ionic/ion-textarea {:placeholder "block content"
                               :ref *input
+                              :class "bg-gray-100"
                               :auto-grow true
                               :autofocus true
                               :value (:block/title block)})]
-        [:div.flex.py-2
+        [:div.flex.py-2.justify-between
+         (ionic/ion-button
+           {:on-click #(close!)
+            :fill "clear"}
+           "Cancel")
          (ionic/ion-button
            {:on-click (fn []
                         (let [new? (nil? (:db/id block))
@@ -59,14 +72,14 @@
                               (p/then (fn []
                                         (close!)
                                         (reload-page!)))))))
-            :class "w-full"} "Save")]))))
+            :class ""} "Save")]))))
 
 (defn nav-to-edit-block!
   [block opts]
   (some-> @state/*nav-root
     (.push #(edit-block-modal block opts))))
 
-(rum/defc page [block]
+(rum/defc page [block {:keys [reload-pages!]}]
   (let [[^js nav] (state/use-nav-root)
         [page set-page!] (rum/use-state (db-utils/entity (:db/id block)))
         title (or (:block/title block) (:block.temp/cached-title block))
@@ -97,7 +110,13 @@
               (ionic/tabler-icon "refresh" {:size 26}))
             (ionic/ion-button {:fill "clear"
                                :class "opacity-80 text-red-500"
-                               :on-click #(.pop nav)}
+                               :on-click (fn []
+                                           (page-handler/<delete! (:block/uuid block)
+                                             (fn []
+                                               (.pop nav)
+                                               (reload-pages!))
+                                             {:error-handler (fn [^js e]
+                                                               (js/console.error e))}))}
               (ionic/tabler-icon "trash" {:size 26})))
 
           (ionic/ion-title title)))

+ 2 - 2
src/main/capacitor/pages/utils.cljs

@@ -3,9 +3,9 @@
             [capacitor.pages.blocks :as page-blocks]))
 
 (defn nav-to-block!
-  [page-or-block]
+  [page-or-block opts]
   (some-> @state/*nav-root
-    (.push #(page-blocks/page page-or-block))))
+    (.push #(page-blocks/page page-or-block opts))))
 
 (defn nav-to-edit-block!
   [block opts]