Browse Source

fix: redirect to the new page when page property title changed

Tienson Qin 4 years ago
parent
commit
55074dec1c
2 changed files with 13 additions and 1 deletions
  1. 9 1
      src/main/frontend/handler/editor.cljs
  2. 4 0
      src/main/frontend/handler/events.cljs

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

@@ -348,7 +348,15 @@
        (when refresh?
          (let [opts {:key :block/change
                      :data [block]}]
-           (db/refresh! repo opts)))))
+           (db/refresh! repo opts)))
+
+       ;; page title changed
+       (when-let [title (get-in block [:block/properties :title])]
+         (when-let [old-title (:block/name (db/entity (:db/id (:block/page block))))]
+           (when (and (:block/pre-block? block)
+                     (not (string/blank? title))
+                     (not= (string/lower-case title) old-title))
+             (state/pub-event! [:page/title-property-changed old-title title]))))))
 
     (repo-handler/push-if-auto-enabled! repo)))
 

+ 4 - 0
src/main/frontend/handler/events.cljs

@@ -9,6 +9,7 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.common :as common-handler]
             [frontend.handler.editor :as editor-handler]
+            [frontend.handler.page :as page-handler]
             [frontend.components.encryption :as encryption]
             [frontend.fs.nfs :as nfs]
             [frontend.db.conn :as conn]
@@ -133,6 +134,9 @@
 (defmethod handle :modal/show-cards [_]
   (state/set-modal! srs/global-cards))
 
+(defmethod handle :page/title-property-changed [[_ old-title new-title]]
+  (page-handler/rename! old-title new-title))
+
 (defmethod handle :after-db-restore [[_ repos]]
   (mapv (fn [{url :url} repo]
           ;; compare :ast/version