From 4859ecd7ea3ccba09a28e13260768ff0e9405b88 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 27 Aug 2024 21:14:13 +0800 Subject: [PATCH] fix: page title shouldn't be blank --- deps/outliner/src/logseq/outliner/core.cljs | 13 ++++++++----- src/main/frontend/components/page.cljs | 1 + src/main/frontend/handler/editor.cljs | 8 +++++--- src/main/frontend/mixins.cljs | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/deps/outliner/src/logseq/outliner/core.cljs b/deps/outliner/src/logseq/outliner/core.cljs index 89a44d85e2..1253718f8d 100644 --- a/deps/outliner/src/logseq/outliner/core.cljs +++ b/deps/outliner/src/logseq/outliner/core.cljs @@ -257,11 +257,14 @@ block-uuid (:block/uuid this) eid (or db-id (when block-uuid [:block/uuid block-uuid])) block-entity (d/entity db eid) - m* (if (and (ldb/page? block-entity) - (:block/title m*) - (not= (string/trim (:block/title m*)) - (string/trim (:block/title block-entity)))) - (assoc m* :block/name (common-util/page-name-sanity-lc (string/trim (:block/title m*)))) + page? (ldb/page? block-entity) + page-title-changed? (and page? (:block/title m*) + (not= (:block/title m*) (:block/title block-entity))) + m* (if (and db-based? page-title-changed?) + (let [page-name (common-util/page-name-sanity-lc (:block/title m*))] + (when (string/blank? page-name) + (throw (ex-info "Page title shouldn't be blank" m*))) + (assoc m* :block/name page-name)) m*) m (cond-> m* db-based? diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 8285c68f8f..a02b25d86c 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -614,6 +614,7 @@ (component-block/breadcrumb config repo block-id {:level-limit 3})])) (page-blocks-cp repo page (merge option {:sidebar? sidebar? + :container-id (:container-id state) :whiteboard? whiteboard?}))]) (when (and (not preview?) @(::main-ready? state)) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 97f4f505eb..9819a00aa2 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1102,12 +1102,14 @@ (let [repo (state/get-current-repo) block-uuids (distinct (map #(uuid (dom/attr % "blockid")) dom-blocks)) lookup-refs (map (fn [id] [:block/uuid id]) block-uuids) - blocks (db/pull-many repo '[*] lookup-refs) - top-level-blocks (block-handler/get-top-level-blocks blocks) + blocks (->> (map db/entity lookup-refs) + (remove ldb/page?)) + top-level-blocks (when (seq blocks) (block-handler/get-top-level-blocks blocks)) sorted-blocks (mapcat (fn [block] (tree/get-sorted-block-and-children repo (:db/id block))) top-level-blocks)] - (delete-blocks! repo (map :block/uuid sorted-blocks) sorted-blocks dom-blocks)))))) + (when (seq sorted-blocks) + (delete-blocks! repo (map :block/uuid sorted-blocks) sorted-blocks dom-blocks))))))) (def url-regex "Didn't use link/plain-link as it is incorrectly detects words as urls." diff --git a/src/main/frontend/mixins.cljs b/src/main/frontend/mixins.cljs index 79c91c6d57..640fa235be 100644 --- a/src/main/frontend/mixins.cljs +++ b/src/main/frontend/mixins.cljs @@ -144,7 +144,7 @@ {:init (fn [state] (let [config (first (:rum/args state)) key (select-keys config [:id :sidebar? :whiteboard? :embed? :custom-query? :query :current-block]) - container-id (state/get-container-id key)] + container-id (or (:container-id config) (state/get-container-id key))] (assoc state :container-id container-id)))}) (defn perf-measure-mixin