fix: don't show delete button for blocks

Also, remove the unused refresh button
This commit is contained in:
Tienson Qin
2025-06-01 06:38:20 +08:00
parent 16d86daab9
commit f7acef9cd2
6 changed files with 206 additions and 214 deletions

View File

@@ -94,24 +94,24 @@ EXTERNAL SOURCES:
:path: "../../node_modules/send-intent"
SPEC CHECKSUMS:
Capacitor: 03bc7cbdde6a629a8b910a9d7d78c3cc7ed09ea7
CapacitorActionSheet: 4213427449132ae4135674d93010cb011725647e
CapacitorApp: febecbb9582cb353aed037e18ec765141f880fe9
CapacitorCamera: 6e73f1fc6c629a672658705a02409b60854bc0f1
CapacitorClipboard: 70bfdb42b877b320a6e511ab94fa7a6a55d57ecb
Capacitor: 106e7a4205f4618d582b886a975657c61179138d
CapacitorActionSheet: 24609588961cc27c87e8b033be92b5eee65b5d4c
CapacitorApp: d63334c052278caf5d81585d80b21905c6f93f39
CapacitorCamera: eb8687d8687fed853598ec9460d94bcd5e16babe
CapacitorClipboard: b98aead5dc7ec595547fc2c5d75bacd2ae3338bc
CapacitorCordova: 5967b9ba03915ef1d585469d6e31f31dc49be96f
CapacitorFilesystem: e6261c410436f54908c11f94336c5b58286b1db0
CapacitorHaptics: 1f1e17041f435d8ead9ff2a34edd592c6aa6a8d6
CapacitorKeyboard: 09fd91dcde4f8a37313e7f11bde553ad1ed52036
CapacitorNetwork: 15cb4385f0913a8ceb5e9a4d7af1ec554bdb8de8
CapacitorShare: e573823f511f260f598d0423c33b1e3d7bbe5fd1
CapacitorSplashScreen: 1d67815a422a9b61539c94f283c08ed56667c0fc
CapacitorStatusBar: 6e7af040d8fc4dd655999819625cae9c2d74c36f
CapacitorVoiceRecorder: d07f0794998ff8c9a6ca3debd70070b286f70cb1
CapawesomeCapacitorBackgroundTask: e17ea2608e9bdd14889d8eba2d793ff9c337db6c
CapgoCapacitorNavigationBar: 3924b761f44960458d2df426bd2a45b6606545f9
JcesarmobileSslSkip: 5fa98636a64c36faa50f32ab4daf34e38f4d45b9
SendIntent: 9456200af151debe8319b62e687a3b3992e6fa64
CapacitorFilesystem: 307f97c27a265edf8396a1c9c235592fd8572fe3
CapacitorHaptics: 70e47470fa1a6bd6338cd102552e3846b7f9a1b3
CapacitorKeyboard: 969647d0ca2e5c737d7300088e2517aa832434e2
CapacitorNetwork: 07ec4c69c1bb696f41c23e00d31bda1bbb221bba
CapacitorShare: 58d6c2da63b093e8693287b2d36db92435538435
CapacitorSplashScreen: 19cd3573e57507e02d6f34597a8c421e00931487
CapacitorStatusBar: 275cbf2f4dfc00388f519ef80c7ec22edda342c9
CapacitorVoiceRecorder: 872ea857b497ce2c71afe3e4eb5de0a74290c0db
CapawesomeCapacitorBackgroundTask: 834d797abc9933fac4354490d1a2f3c0e389b98d
CapgoCapacitorNavigationBar: 3a0e93a40b7da3d3cb74c0410bb761a1525406be
JcesarmobileSslSkip: b0f921e9d397a57f7983731209ca1ee244119c1f
SendIntent: 0a17b6984c4f27e9dfa56513267ba2c044a5a6c8
PODFILE CHECKSUM: 6ad6123989fe311fd59e42e4371f1ce440fc2516

View File

@@ -41,47 +41,47 @@
"Select a Graph")]
[:.app-graph-select
(ion/button
{:fill "clear"
:mode "ios"
:class "border-none w-full rounded-lg"
:on-click (fn []
(let [buttons (concat
(for [repo graphs]
{:text (some-> (:url repo) (string/replace #"^logseq_db_" ""))
:role (:url repo)})
[{:text "+ Add new graph"
:role "add-new-graph"}])]
(ui-component/open-modal! "Switch graph"
{:type :action-sheet
:buttons buttons
:inputs []
:on-action (fn [e]
(when-let [role (:role e)]
(if (= "add-new-graph" role)
(when-let [db-name (js/prompt "Create new db")]
(when-not (string/blank? db-name)
(repo-handler/new-db! db-name)))
(when (string/starts-with? role "logseq_db_")
(fstate/pub-event! [:graph/switch role])))))})))}
[:span.flex.items-center.gap-2.opacity-80.pt-1
[:strong.overflow-hidden.text-ellipsis.block.font-normal
{:style {:max-width "40vw"}}
short-repo-name]])]))
{:fill "clear"
:mode "ios"
:class "border-none w-full rounded-lg"
:on-click (fn []
(let [buttons (concat
(for [repo graphs]
{:text (some-> (:url repo) (string/replace #"^logseq_db_" ""))
:role (:url repo)})
[{:text "+ Add new graph"
:role "add-new-graph"}])]
(ui-component/open-modal! "Switch graph"
{:type :action-sheet
:buttons buttons
:inputs []
:on-action (fn [e]
(when-let [role (:role e)]
(if (= "add-new-graph" role)
(when-let [db-name (js/prompt "Create new db")]
(when-not (string/blank? db-name)
(repo-handler/new-db! db-name)))
(when (string/starts-with? role "logseq_db_")
(fstate/pub-event! [:graph/switch role])))))})))}
[:span.flex.items-center.gap-2.opacity-80.pt-1
[:strong.overflow-hidden.text-ellipsis.block.font-normal
{:style {:max-width "40vw"}}
short-repo-name]])]))
(rum/defc bottom-tabs
[]
(ion/tab-bar
{:slot "bottom"}
(ion/tab-button
{:tab "home"
:selected true}
(ion/tabler-icon "home" {:size 22}) "Journals")
(ion/tab-button
{:tab "search"}
(ion/tabler-icon "search" {:size 22}) "Search")
(ion/tab-button
{:tab "settings"}
(ion/tabler-icon "settings" {:size 22}) "Settings")))
{:slot "bottom"}
(ion/tab-button
{:tab "home"
:selected true}
(ion/tabler-icon "home" {:size 22}) "Journals")
(ion/tab-button
{:tab "search"}
(ion/tabler-icon "search" {:size 22}) "Search")
(ion/tab-button
{:tab "settings"}
(ion/tabler-icon "settings" {:size 22}) "Settings")))
(rum/defc keep-keyboard-open
[]
@@ -92,169 +92,168 @@
[]
(let [show-action-bar? (fstate/sub :mobile/show-action-bar?)]
(ion/content
(ui-component/classic-app-container-wrap
[:div.pt-3
(journal/all-journals)
(when show-action-bar?
(action-bar/action-bar))]))))
(ui-component/classic-app-container-wrap
[:div.pt-3
(journal/all-journals)
(when show-action-bar?
(action-bar/action-bar))]))))
(rum/defc home < rum/reactive
{:did-mount (fn [state]
(ui/inject-document-devices-envs!)
state)}
{:did-mount (fn [state]
(ui/inject-document-devices-envs!)
state)}
[]
(let [db-restoring? (fstate/sub :db/restoring?)]
(ion/page
{:id "app-main-content"}
(ion/header
(ion/toolbar
(ion/buttons {:slot "start"}
(app-graphs-select))
{:id "app-main-content"}
(ion/header
(ion/toolbar
(ion/buttons {:slot "start"}
(app-graphs-select))
(ion/buttons {:slot "end"}
(ion/button
{:size "small"
:fill "clear"
:on-click (fn []
(let [apply-date! (fn [date]
(let [page-name (date/journal-name (gdate/Date. (js/Date. date)))
nav-to-journal! #(nav/nav-to-block! % {:reload-pages! (fn [] ())})]
(if-let [journal (db/get-page page-name)]
(nav-to-journal! journal)
(-> (page-handler/<create! page-name {:redirect? false})
(p/then #(nav-to-journal! (db/get-page page-name)))))))]
(ion/buttons {:slot "end"}
(ion/button
{:size "small"
:fill "clear"
:on-click (fn []
(let [apply-date! (fn [date]
(let [page-name (date/journal-name (gdate/Date. (js/Date. date)))]
(if-let [journal (db/get-page page-name)]
(nav/nav-to-block! journal)
(-> (page-handler/<create! page-name {:redirect? false})
(p/then #(nav/nav-to-block! (db/get-page page-name)))))))]
(if (mobile-util/native-platform?)
(-> (.showDatePicker mobile-util/ui-local)
(p/then (fn [^js e] (some-> e (.-value) (apply-date!)))))
(if (mobile-util/native-platform?)
(-> (.showDatePicker mobile-util/ui-local)
(p/then (fn [^js e] (some-> e (.-value) (apply-date!)))))
(ui-component/open-modal!
(fn [{:keys [close!]}]
(ion/datetime
{:presentation "date"
:onIonChange (fn [^js e]
(let [val (.-value (.-detail e))]
(apply-date! val)
(close!)))}))))))}
[:span.text-muted-foreground {:slot "icon-only"}
(ion/tabler-icon "calendar-month" {:size 24})])
(ui-component/open-modal!
(fn [{:keys [close!]}]
(ion/datetime
{:presentation "date"
:onIonChange (fn [^js e]
(let [val (.-value (.-detail e))]
(apply-date! val)
(close!)))}))))))}
[:span.text-muted-foreground {:slot "icon-only"}
(ion/tabler-icon "calendar-month" {:size 24})])
(let [repo (fstate/get-current-repo)]
[:div.flex.flex-row.items-center.gap-2.text-muted-foreground
(when (and repo
(ldb/get-graph-rtc-uuid (db/get-db))
(user-handler/logged-in?)
(config/db-based-graph? repo)
(user-handler/team-member?))
[:<>
(let [repo (fstate/get-current-repo)]
[:div.flex.flex-row.items-center.gap-2.text-muted-foreground
(when (and repo
(ldb/get-graph-rtc-uuid (db/get-db))
(user-handler/logged-in?)
(config/db-based-graph? repo)
(user-handler/team-member?))
[:<>
;; (rum/with-key (rtc-collaborators)
;; (str "collab-" repo))
(rtc-indicator/indicator)
(rtc-indicator/indicator)
;; (when (user-handler/logged-in?)
;; (rtc-indicator/downloading-detail))
;; (when (user-handler/logged-in?)
;; (rtc-indicator/uploading-detail))
])]))))
])]))))
;; main content
(if db-restoring?
(ion/content
[:strong.flex.justify-center.items-center.py-24
(ion/tabler-icon "loader" {:class "animate animate-spin opacity-50" :size 30})])
(journals)))))
(if db-restoring?
(ion/content
[:strong.flex.justify-center.items-center.py-24
(ion/tabler-icon "loader" {:class "animate animate-spin opacity-50" :size 30})])
(journals)))))
(rum/defc settings
[]
(ion/page
{:id "settings-tab"}
(ion/header
(ion/toolbar
"Settings"))
[:div.flex.flex-1.p-4 "TODO..."]))
{:id "settings-tab"}
(ion/header
(ion/toolbar
"Settings"))
[:div.flex.flex-1.p-4 "TODO..."]))
(rum/defc tabs
[]
(let [nav-ref (hooks/use-ref nil)
[_ set-nav-root!] (state/use-nav-root)]
(hooks/use-effect!
(fn []
(when-let [nav (rum/deref nav-ref)]
(set-nav-root! nav))
#())
[(rum/deref nav-ref)])
(fn []
(when-let [nav (rum/deref nav-ref)]
(set-nav-root! nav))
#())
[(rum/deref nav-ref)])
(ion/tabs
{:onIonTabsDidChange (fn [^js e]
(state/set-tab! (.-tab (.-detail e))))}
(ion/tab
{:tab "home"}
(ion/nav {:ref nav-ref
:root home ;;settings/page
:animated true
:swipeGesture true}))
(ion/tab
{:tab "search"}
(ion/content
(search/search)))
(ion/tab
{:tab "settings"}
(ion/content
(settings/page)))
(bottom-tabs)
{:onIonTabsDidChange (fn [^js e]
(state/set-tab! (.-tab (.-detail e))))}
(ion/tab
{:tab "home"}
(ion/nav {:ref nav-ref
:root home ;;settings/page
:animated true
:swipeGesture true}))
(ion/tab
{:tab "search"}
(ion/content
(search/search)))
(ion/tab
{:tab "settings"}
(ion/content
(settings/page)))
(bottom-tabs)
(keep-keyboard-open)
(ui-component/install-notifications)
(ui-component/install-modals)
(keep-keyboard-open)
(ui-component/install-notifications)
(ui-component/install-modals)
(shui-toaster/install-toaster)
(shui-dialog/install-modals)
(shui-popup/install-popups))))
(shui-toaster/install-toaster)
(shui-dialog/install-modals)
(shui-popup/install-popups))))
(defn use-theme-effects!
[current-repo]
(let [[theme] (frum/use-atom-in fstate/state :ui/theme)]
(hooks/use-effect!
#(let [^js doc js/document.documentElement
^js cls (.-classList doc)
^js cls-body (.-classList js/document.body)]
(.setAttribute doc "data-theme" theme)
(if (= theme "dark") ;; for tailwind dark mode
(do (.add cls "dark") (.add cls "ion-palette-dark")
(doto cls-body (.remove "light-theme") (.add "dark-theme")))
(do (.remove cls "dark") (.remove cls "ion-palette-dark")
(doto cls-body (.remove "dark-theme") (.add "light-theme")))))
[theme]))
#(let [^js doc js/document.documentElement
^js cls (.-classList doc)
^js cls-body (.-classList js/document.body)]
(.setAttribute doc "data-theme" theme)
(if (= theme "dark") ;; for tailwind dark mode
(do (.add cls "dark") (.add cls "ion-palette-dark")
(doto cls-body (.remove "light-theme") (.add "dark-theme")))
(do (.remove cls "dark") (.remove cls "ion-palette-dark")
(doto cls-body (.remove "dark-theme") (.add "light-theme")))))
[theme]))
(hooks/use-effect!
(fn []
(some-> js/window.externalsjs (.settleStatusBar)))
[current-repo]))
(fn []
(some-> js/window.externalsjs (.settleStatusBar)))
[current-repo]))
(defn use-navigation-effects!
[]
(hooks/use-effect!
(fn []
(let [handle-back!
(fn []
(cond
(seq (ui-component/get-modal))
(ui-component/close-modal!)
(fn []
(let [handle-back!
(fn []
(cond
(seq (ui-component/get-modal))
(ui-component/close-modal!)
(seq (shui-dialog/get-modal (shui-dialog/get-first-modal-id)))
(shui-dialog/close!)
(seq (shui-dialog/get-modal (shui-dialog/get-first-modal-id)))
(shui-dialog/close!)
(seq (fstate/get-selection-blocks))
(fstate/clear-selection!)
(seq (fstate/get-selection-blocks))
(fstate/clear-selection!)
:else
(-> (nav/nav-length?)
(p/then (fn [len]
(if (= len 1)
(.exitApp App)
(nav/nav-pop!))))))
(fstate/clear-edit!))
^js back-listener (.addListener App "backButton" handle-back!)]
#(.remove back-listener)))
[]))
:else
(-> (nav/nav-length?)
(p/then (fn [len]
(if (= len 1)
(.exitApp App)
(nav/nav-pop!))))))
(fstate/clear-edit!))
^js back-listener (.addListener App "backButton" handle-back!)]
#(.remove back-listener)))
[]))
(rum/defc main []
(let [[current-repo] (frum/use-atom-in fstate/state :git/current-repo)]

View File

@@ -1,32 +1,31 @@
(ns capacitor.components.page
(:require [capacitor.ionic :as ion]
(:require [capacitor.components.ui :as ui]
[capacitor.ionic :as ion]
[capacitor.state :as state]
[capacitor.components.ui :as ui]
[frontend.components.page :as cp-page]
[frontend.db.async :as db-async]
[frontend.db.utils :as db-utils]
[frontend.handler.page :as page-handler]
[frontend.state :as fstate]
[logseq.db :as ldb]
[promesa.core :as p]
[rum.core :as rum]))
(rum/defc page
[block & {:keys [reload-pages!]}]
[block]
(let [[^js nav] (state/use-nav-root)
[page set-page!] (rum/use-state (let [eid (or (:db/id block)
(when-let [id (:block/uuid block)]
[:block/uuid id]))]
(db-utils/entity eid)))
title (or (:block/title block) (:block/title page))
[loading? set-loading!] (rum/use-state true)
rerender! (fn []
(set-page! (db-utils/entity (:db/id block))))]
[entity set-entity!] (rum/use-state (let [eid (or (:db/id block)
(when-let [id (:block/uuid block)]
[:block/uuid id]))]
(db-utils/entity eid)))
title (or (:block/title block) (:block/title entity))
[loading? set-loading!] (rum/use-state true)]
(rum/use-effect!
;; sync page blocks
(fn []
(-> (db-async/<get-block (fstate/get-current-repo) (:block/uuid block))
(p/then #(set-page! (db-utils/entity (:db/id %))))
(p/then #(set-entity! (db-utils/entity (:db/id %))))
(p/finally #(set-loading! false)))
#())
[])
@@ -38,28 +37,22 @@
(ion/button {:fill "clear"
:on-click #(.pop nav)}
(ion/tabler-icon "arrow-left" {:size 26})))
(ion/buttons {:slot "end"}
(ion/button {:fill "clear"
:class "opacity-80"
:on-click rerender!}
(ion/tabler-icon "refresh" {:size 26}))
(ion/button {:fill "clear"
:class "opacity-80 text-red-500"
:on-click (fn []
(page-handler/<delete! (:block/uuid block)
(fn []
(.pop nav)
(when (fn? reload-pages!)
(reload-pages!)))
{:error-handler (fn [^js e]
(js/console.error e))}))}
(ion/tabler-icon "trash" {:size 26})))
(when (ldb/page? entity)
(ion/buttons {:slot "end"}
(ion/button {:fill "clear"
:on-click (fn []
(page-handler/<delete! (:block/uuid entity)
(fn []
(.pop nav))
{:error-handler (fn [^js e]
(js/console.error e))}))}
[:span.text-muted-foreground {:slot "icon-only"}
(ion/tabler-icon "trash" {:size 24})])))
(ion/title title)))
(ion/content {:class "ion-padding"}
(ui/classic-app-container-wrap
(if loading?
[:p.text-xl.text-center "Loading ..."]
(cp-page/page-blocks-cp page {})))))))
(ion/content {:class "ion-padding"}
(ui/classic-app-container-wrap
(if loading?
[:p.text-xl.text-center "Loading ..."]
(cp-page/page-blocks-cp entity {})))))))

View File

@@ -119,7 +119,7 @@
{:on-click (fn []
(state/set-tab! "home")
(.select (dom/sel1 "ion-tabs") "home")
(nav/nav-to-block! block {}))}
(nav/nav-to-block! block))}
[:div.flex.flex-col.gap-1.py-1
(when header
[:div.opacity-50.text-sm

View File

@@ -41,7 +41,7 @@
(let [id-str (get-in route [:path-params :name])]
(when (util/uuid-string? id-str)
(let [page-uuid (uuid id-str)]
(nav/nav-to-block! {:block/uuid page-uuid} nil))))
(nav/nav-to-block! {:block/uuid page-uuid}))))
:user-login
nil
nil))

View File

@@ -1,13 +1,13 @@
(ns capacitor.nav
(:require [capacitor.state :as state]
[capacitor.components.page :as page]
(:require [capacitor.components.page :as page]
[capacitor.state :as state]
[cljs-bean.core :as bean]))
;; https://ionicframework.com/docs/api/nav#push
(defn nav-push!
[component & opts]
(some-> @state/*nav-root
(.push component (bean/->js opts))))
(.push component (bean/->js opts))))
(defn nav-pop! []
(some-> @state/*nav-root (.pop)))
@@ -16,5 +16,5 @@
(some-> ^js @state/*nav-root (.getLength)))
(defn nav-to-block!
[page-or-block opts]
(nav-push! #(page/page page-or-block opts)))
[page-or-block]
(nav-push! #(page/page page-or-block)))