mirror of https://github.com/logseq/logseq
fix both page create and delete
parent
1e72d0efc7
commit
7c4baf97db
|
@ -13,7 +13,8 @@
|
|||
[frontend.handler.ui :as ui-handler]
|
||||
[frontend.config :as config]
|
||||
[frontend.fs :as fs]
|
||||
[promesa.core :as p]))
|
||||
[promesa.core :as p]
|
||||
[frontend.handler.block :as block-handler]))
|
||||
|
||||
(defn create!
|
||||
"Create page. Has the following options:
|
||||
|
@ -37,6 +38,8 @@
|
|||
(when-let [page-name (worker-page/create! repo conn config title options)]
|
||||
(when redirect?
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page-name))))
|
||||
|
||||
;; favorite fns
|
||||
|
|
|
@ -53,9 +53,8 @@
|
|||
tx-report {:tx-meta tx-meta
|
||||
:tx-data tx-data}]
|
||||
|
||||
(when-let [file-path (and (= (:outliner-op tx-meta) :delete-page)
|
||||
(:file-path tx-meta))]
|
||||
(state/pub-event! [:page/deleted repo (:deleted-page tx-meta) file-path]))
|
||||
(when (= (:outliner-op tx-meta) :delete-page)
|
||||
(state/pub-event! [:page/deleted repo (:deleted-page tx-meta) (:file-path tx-meta)]))
|
||||
|
||||
(when-not (or from-disk? new-graph?)
|
||||
(try
|
||||
|
|
|
@ -97,18 +97,18 @@
|
|||
(assoc page :block/namespace
|
||||
[:block/uuid (:block/uuid (nth txs (dec i)))])))
|
||||
txs)
|
||||
last-txs (build-page-tx repo conn config date-formatter format properties (last pages) (select-keys options [:whiteboard? :class? :tags]))
|
||||
last-txs (if (seq txs)
|
||||
(update last-txs 0
|
||||
page-txs (build-page-tx repo conn config date-formatter format properties (last pages) (select-keys options [:whiteboard? :class? :tags]))
|
||||
page-txs (if (seq txs)
|
||||
(update page-txs 0
|
||||
(fn [p]
|
||||
(assoc p :block/namespace [:block/uuid (:block/uuid (last txs))])))
|
||||
last-txs)
|
||||
page-txs)
|
||||
first-block-tx (when (and
|
||||
create-first-block?
|
||||
(not (or whiteboard? class?))
|
||||
(ldb/page-empty? @conn (:db/id (d/entity @conn [:block/name page-name])))
|
||||
(seq txs))
|
||||
(let [page-id [:block/uuid (:block/uuid (last txs))]]
|
||||
page-txs)
|
||||
(let [page-id [:block/uuid (:block/uuid (first page-txs))]]
|
||||
[(sqlite-util/block-with-timestamps
|
||||
{:block/uuid (ldb/new-block-id)
|
||||
:block/page page-id
|
||||
|
@ -122,13 +122,12 @@
|
|||
[[:db/retract (:db/id e) :block/namespace]
|
||||
[:db/retract (:db/id e) :block/refs]]))
|
||||
txs
|
||||
last-txs
|
||||
page-txs
|
||||
first-block-tx)]
|
||||
(when (seq txs)
|
||||
(d/transact! conn txs {:persist-op? persist-op?})
|
||||
page-name)))))
|
||||
|
||||
|
||||
(defn db-refs->page
|
||||
"Replace [[page name]] with page name"
|
||||
[repo page-entity]
|
||||
|
@ -176,13 +175,13 @@
|
|||
(try
|
||||
(cond
|
||||
(and (contains? (:block/type page) "class")
|
||||
(seq (ldb/get-tag-blocks conn (:block/name page))))
|
||||
(seq (ldb/get-tag-blocks @conn (:block/name page))))
|
||||
{:msg "Page content deleted but unable to delete this page because blocks are tagged with this page"}
|
||||
|
||||
(contains? (:block/type page) "property")
|
||||
(cond (seq (ldb/get-classes-with-property conn (:block/uuid page)))
|
||||
(cond (seq (ldb/get-classes-with-property @conn (:block/uuid page)))
|
||||
{:msg "Page content deleted but unable to delete this page because classes use this property"}
|
||||
(seq (ldb/get-block-property-values conn (:block/uuid page)))
|
||||
(seq (ldb/get-block-property-values @conn (:block/uuid page)))
|
||||
{:msg "Page content deleted but unable to delete this page because blocks use this property"})
|
||||
|
||||
(or (seq (:block/_refs page)) (contains? (:block/type page) "hidden"))
|
||||
|
@ -219,7 +218,7 @@
|
|||
;; then just remove some attrs of this entity instead of retractEntity
|
||||
delete-page-tx (cond
|
||||
(not (:block/_namespace page))
|
||||
(if (ldb/get-alias-source-page conn page-name)
|
||||
(if (ldb/get-alias-source-page @conn page-name)
|
||||
(when-let [id (:db/id (d/entity @conn [:block/name page-name]))]
|
||||
(mapv (fn [attribute]
|
||||
[:db/retract id attribute])
|
||||
|
|
Loading…
Reference in New Issue