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