From 067d3beba24311e2eaa3305e6f0f63ed7fe29b4d Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 15 Aug 2023 17:06:24 +0800 Subject: [PATCH] show linked page instead of the block that the page has been added --- src/main/frontend/components/block.cljs | 8 ++- src/main/frontend/modules/outliner/core.cljs | 55 +++++++++---------- .../frontend/modules/outliner/datascript.cljs | 4 +- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 0765557c55..1e60bee7c4 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2348,6 +2348,9 @@ (when-not plugin-slotted? [:div.flex-1.w-full (cond + (:block/original-name block) + (page-cp config block) + (or (seq title) (:block/marker block)) (build-block-title config block) @@ -2369,7 +2372,7 @@ (when-not (config/db-based-graph? repo) (when-let [invalid-properties (:block/invalid-properties block)] - (invalid-properties-cp invalid-properties))) + (invalid-properties-cp invalid-properties))) (when (and (seq properties) (let [hidden? (file-property/properties-hidden? properties)] @@ -3343,7 +3346,8 @@ (defn- block-item [config blocks idx item] - (let [item (-> + (let [item (or (:block/link item) item) + item (-> (dissoc item :block/meta) (assoc :block.temp/top? (zero? idx) :block.temp/bottom? (= (count blocks) (inc idx)))) diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index 2a1761cce9..bfbeacfa99 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -19,7 +19,8 @@ [frontend.handler.file-based.property.util :as property-util] [frontend.handler.property.util :as pu] [frontend.db.rtc.op :as rtc-op] - [clojure.core.async :as async])) + [clojure.core.async :as async] + [frontend.format.mldoc :as mldoc])) (s/def ::block-map (s/keys :opt [:db/id :block/uuid :block/page :block/left :block/parent])) @@ -131,21 +132,15 @@ (defn- assoc-linked-block-when-save [txs-state block-entity m] - (let [tags (seq (:block/tags m))] - (when (and (config/db-based-graph? (state/get-current-repo)) - (:block/page block-entity) - tags) - (let [tag-names (set (map :block/name tags))] - (when-let [linked-block-id (:block/uuid - (first (remove (fn [ref] - (contains? tag-names (:block/name ref))) - (:block/refs m))))] - (swap! txs-state (fn [txs] - (concat txs - [{:block/uuid linked-block-id - :block/tags (:block/tags m)} - {:db/id (:db/id block-entity) - :block/link [:block/uuid linked-block-id]}])))))))) + (let [linked-page (some-> (:block/content m) mldoc/extract-plain) + sanity-linked-page (util/page-name-sanity-lc linked-page)] + (when-not (string/blank? sanity-linked-page) + (let [page-m (block/page-name->map linked-page true)] + (swap! txs-state (fn [txs] + (concat txs + [(assoc page-m :block/tags (:block/tags m)) + {:db/id (:db/id block-entity) + :block/link [:block/uuid (:block/uuid page-m)]}]))))))) (defn rebuild-block-refs [block new-properties & {:keys [skip-content-parsing?]}] @@ -250,28 +245,31 @@ (assert (ds/outliner-txs-state? txs-state) "db should be satisfied outliner-tx-state?") (let [m* (-> (:data this) - (dissoc :block/children :block/meta :block.temp/top? :block.temp/bottom? - :block/title :block/body :block/level) - gp-util/remove-nils - block-with-timestamps - fix-tag-ids) + (dissoc :block/children :block/meta :block.temp/top? :block.temp/bottom? + :block/title :block/body :block/level) + gp-util/remove-nils + block-with-timestamps + fix-tag-ids) repo (state/get-current-repo) db-based? (config/db-based-graph? repo) m (if db-based? (dissoc m* :block/properties :block/properties-order) m*) id (:db/id (:data this)) - block-entity (db/entity id)] + block-entity (db/entity id) + structured-tags? (and (config/db-based-graph? (state/get-current-repo)) + (:block/page block-entity) + (seq (:block/tags m)))] (when id ;; Retract attributes to prepare for tx which rewrites block attributes (let [retract-attributes (if db-based? (remove #{:block/properties :block/properties-order} db-schema/retract-attributes))] (swap! txs-state (fn [txs] - (vec - (concat txs - (map (fn [attribute] - [:db/retract id attribute]) - retract-attributes)))))) + (vec + (concat txs + (map (fn [attribute] + [:db/retract id attribute]) + retract-attributes)))))) ;; Update block's page attributes (update-page-when-save-block txs-state block-entity m) @@ -286,7 +284,8 @@ (vec (concat txs other-tx))))) (swap! txs-state conj (dissoc m :db/other-tx))) - (assoc-linked-block-when-save txs-state block-entity m) + (when structured-tags? + (assoc-linked-block-when-save txs-state block-entity m)) (rebuild-refs txs-state block-entity m) diff --git a/src/main/frontend/modules/outliner/datascript.cljs b/src/main/frontend/modules/outliner/datascript.cljs index 7b755151f5..efa8f254d7 100644 --- a/src/main/frontend/modules/outliner/datascript.cljs +++ b/src/main/frontend/modules/outliner/datascript.cljs @@ -171,8 +171,8 @@ (not (contains? (:file/unlinked-dirs @state/state) (config/get-repo-dir repo))))) - ;; (prn :debug "Outliner transact:") - ;; (frontend.util/pprint {:txs txs :opts opts}) + (prn :debug "Outliner transact:") + (frontend.util/pprint {:txs txs :opts opts}) (try (let [repo (get opts :repo (state/get-current-repo))