fix: navigate back to previous route after deleting a page

This commit is contained in:
Tienson Qin
2025-11-26 17:29:44 +08:00
parent 357c8f0667
commit 900e845b92
12 changed files with 56 additions and 28 deletions

View File

@@ -16,6 +16,7 @@ dependencies {
implementation project(':capacitor-camera')
implementation project(':capacitor-clipboard')
implementation project(':capacitor-device')
implementation project(':capacitor-dialog')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')

View File

@@ -27,6 +27,10 @@
"pkg": "@capacitor/device",
"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
},
{
"pkg": "@capacitor/dialog",
"classpath": "com.capacitorjs.plugins.dialog.DialogPlugin"
},
{
"pkg": "@capacitor/filesystem",
"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"

View File

@@ -23,6 +23,9 @@ project(':capacitor-clipboard').projectDir = new File('../node_modules/@capacito
include ':capacitor-device'
project(':capacitor-device').projectDir = new File('../node_modules/@capacitor/device/android')
include ':capacitor-dialog'
project(':capacitor-dialog').projectDir = new File('../node_modules/@capacitor/dialog/android')
include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')

View File

@@ -18,6 +18,7 @@ def capacitor_pods
pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera'
pod 'CapacitorClipboard', :path => '../../node_modules/@capacitor/clipboard'
pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog'
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'

View File

@@ -17,6 +17,8 @@ PODS:
- CapacitorCordova (7.2.0)
- CapacitorDevice (7.0.2):
- Capacitor
- CapacitorDialog (7.0.2):
- Capacitor
- CapacitorFilesystem (7.0.1):
- Capacitor
- CapacitorHaptics (7.0.1):
@@ -49,6 +51,7 @@ DEPENDENCIES:
- "CapacitorCommunitySafeArea (from `../../node_modules/@capacitor-community/safe-area`)"
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
- "CapacitorDevice (from `../../node_modules/@capacitor/device`)"
- "CapacitorDialog (from `../../node_modules/@capacitor/dialog`)"
- "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)"
- "CapacitorHaptics (from `../../node_modules/@capacitor/haptics`)"
- "CapacitorKeyboard (from `../../node_modules/@capacitor/keyboard`)"
@@ -83,6 +86,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/ios"
CapacitorDevice:
:path: "../../node_modules/@capacitor/device"
CapacitorDialog:
:path: "../../node_modules/@capacitor/dialog"
CapacitorFilesystem:
:path: "../../node_modules/@capacitor/filesystem"
CapacitorHaptics:
@@ -114,6 +119,7 @@ SPEC CHECKSUMS:
CapacitorCommunitySafeArea: 3f049619072ab5d0da2529bcb05b358ff6c13dc1
CapacitorCordova: 5967b9ba03915ef1d585469d6e31f31dc49be96f
CapacitorDevice: 81ae78d5d1942707caad79276badd458bf6ec603
CapacitorDialog: 5bf72a94b747fb339df6f64ef60812e5e4630ad2
CapacitorFilesystem: e6261c410436f54908c11f94336c5b58286b1db0
CapacitorHaptics: 1f1e17041f435d8ead9ff2a34edd592c6aa6a8d6
CapacitorKeyboard: 09fd91dcde4f8a37313e7f11bde553ad1ed52036
@@ -126,6 +132,6 @@ SPEC CHECKSUMS:
KeychainSwift: 4a71a45c802fd9e73906457c2dcbdbdc06c9419d
SendIntent: 8a6f646a4489f788d253ffbd1082a98ea388d870
PODFILE CHECKSUM: bf3859ae3f2ef96dbee7c801e4be9d91c6e68077
PODFILE CHECKSUM: 2ba428e46e22e2bca616c46fc132c5699b98e54b
COCOAPODS: 1.16.2

View File

@@ -117,6 +117,7 @@
"@capacitor/clipboard": "7.0.1",
"@capacitor/core": "7.2.0",
"@capacitor/device": "^7.0.2",
"@capacitor/dialog": "^7.0.2",
"@capacitor/filesystem": "7.0.1",
"@capacitor/haptics": "7.0.1",
"@capacitor/ios": "7.2.0",

View File

@@ -139,10 +139,12 @@
(page-handler/<create! page-name opts)))
(defmethod handle :page/deleted [[_ repo page-name file-path tx-meta]]
(page-common-handler/after-page-deleted! repo page-name file-path tx-meta))
(when-not (util/mobile?)
(page-common-handler/after-page-deleted! repo page-name file-path tx-meta)))
(defmethod handle :page/renamed [[_ repo data]]
(page-common-handler/after-page-renamed! repo data))
(when-not (util/mobile?)
(page-common-handler/after-page-renamed! repo data)))
(defmethod handle :page/create-today-journal [[_ _repo]]
(p/let [_ (page-handler/create-today-journal!)]

View File

@@ -37,7 +37,8 @@
(let [ids (map (fn [id] (:db/id (db/entity [:block/uuid id]))) deleted-block-uuids)]
(state/sidebar-remove-deleted-block! ids))
(when-let [block-id (state/get-current-page)]
(when (contains? (set (map str deleted-block-uuids)) block-id)
(when (and (contains? (set (map str deleted-block-uuids)) block-id)
(not (util/mobile?)))
(let [parent (:block/parent (ldb/get-page (db/get-db) block-id))]
(if parent
(route-handler/redirect-to-page! (:block/uuid parent))

View File

@@ -1,6 +1,7 @@
(ns mobile.components.header
"App top header"
(:require [clojure.string :as string]
(:require ["@capacitor/dialog" :refer [Dialog]]
[clojure.string :as string]
[frontend.common.missionary :as c.m]
[frontend.components.repo :as repo]
[frontend.components.rtc.indicator :as rtc-indicator]
@@ -132,22 +133,27 @@
"Copy"])
(ui/menu-link
{:on-click #(-> (shui/dialog-confirm!
(str "⚠️ Are you sure you want to delete this "
(if (entity-util/page? block) "page" "block")
"?"))
(p/then
{:on-click
(fn []
(p/do!
(shui/popup-hide!)
(-> (.confirm ^js Dialog
#js {:title "Confirm"
:message (str "Are you sure to delete this "
(if (entity-util/page? block) "page" "block")
"?")})
(p/then
(fn [^js result]
(let [value (.-value result)]
(when value
(some->
(:block/uuid block)
(page-handler/<delete!
(fn []
(shui/popup-hide!)
(some->
(:block/uuid block)
(page-handler/<delete!
(fn []
;; FIXME: empty screen, wrong route state
(mobile-state/set-tab! "home"))
{:error-handler
(fn [{:keys [msg]}]
(notification/show! msg :warning))})))))}
(js/history.back))
{:error-handler
(fn [{:keys [msg]}]
(notification/show! msg :warning))})))))))))}
[:span.text-lg.flex.gap-2.items-center.text-red-700
(shui/tabler-icon "trash" {:class "opacity-80" :size 22})
"Delete"])])

View File

@@ -17,9 +17,8 @@
[mobile.events]
[mobile.init :as init]
[mobile.navigation :as mobile-nav]
[mobile.routes :refer [routes]]
[mobile.routes :refer [routes] :as mobile-routes]
[mobile.state :as mobile-state]
[promesa.core :as p]
[reitit.frontend :as rf]
[reitit.frontend.easy :as rfe]))

View File

@@ -40,9 +40,8 @@
route (assoc :route route)
(or path (.-hash js/location))
(assoc :path (strip-fragment (or path (.-hash js/location))))))]
(when-not (= nav-type "pop")
(-> (.routeDidChange mobile-util/ui-local payload)
(p/catch (fn [err]
(log/warn :mobile-native-navigation/route-report-failed
{:error err
:payload payload}))))))))
(-> (.routeDidChange mobile-util/ui-local payload)
(p/catch (fn [err]
(log/warn :mobile-native-navigation/route-report-failed
{:error err
:payload payload})))))))

View File

@@ -323,6 +323,11 @@
resolved "https://registry.yarnpkg.com/@capacitor/device/-/device-7.0.2.tgz#406bde129d3fcf55f0de0b691509535e2a00e315"
integrity sha512-OMGMBjLbh7ApaqW1oOJIV73iyrFK/T5v2MzuQYq3GLT+jnGvCuj/y82Ofq2Fz9/hlJ2fukztPwG1K80jyk0i6w==
"@capacitor/dialog@^7.0.2":
version "7.0.2"
resolved "https://registry.yarnpkg.com/@capacitor/dialog/-/dialog-7.0.2.tgz#ff0b50a0fd4d9792fd6e47dcf28e2cee49c41568"
integrity sha512-2lRMKEdBV/2LMCwHbC5a03jiU4tdlIN4hXAqmQMxnaa7CAVLfk/vEE+vxA5mpnI/pzoXF/QDQEUXJUd10hbcKA==
"@capacitor/filesystem@7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@capacitor/filesystem/-/filesystem-7.0.1.tgz#b0518d781f7640e936f529b80a59724e221d0471"