mirror of https://github.com/logseq/logseq
Fix deleting issue
parent
58c23413e8
commit
a4133956c4
|
@ -694,7 +694,7 @@
|
||||||
(state/add-custom-query-component! query (:rum/react-component state)))
|
(state/add-custom-query-component! query (:rum/react-component state)))
|
||||||
state)}
|
state)}
|
||||||
[config options content]
|
[config options content]
|
||||||
[:div.custom-query.my-2
|
[:div.custom-query.my-4
|
||||||
[:code (or (:query-title options)
|
[:code (or (:query-title options)
|
||||||
"Query result: ")]
|
"Query result: ")]
|
||||||
(let [result (db/custom-query content)]
|
(let [result (db/custom-query content)]
|
||||||
|
@ -833,7 +833,7 @@
|
||||||
(if (:group-by-page? config)
|
(if (:group-by-page? config)
|
||||||
(for [[page headings] headings]
|
(for [[page headings] headings]
|
||||||
(let [page (db/entity (:db/id page))]
|
(let [page (db/entity (:db/id page))]
|
||||||
[:div {:key (str "page-" (:db/id page))}
|
[:div.my-2 {:key (str "page-" (:db/id page))}
|
||||||
(page-cp page)
|
(page-cp page)
|
||||||
(headings-cp headings config)]))
|
(headings-cp headings config)]))
|
||||||
(headings-cp headings config))]))
|
(headings-cp headings config))]))
|
||||||
|
|
|
@ -48,8 +48,12 @@
|
||||||
heading? (util/uuid-string? page-name)
|
heading? (util/uuid-string? page-name)
|
||||||
heading-id (and heading? (uuid page-name))
|
heading-id (and heading? (uuid page-name))
|
||||||
sidebar? (:sidebar? option)
|
sidebar? (:sidebar? option)
|
||||||
raw-page-headings (get-headings repo page-name journal? heading?)
|
raw-page-headings (get-headings repo page-name journal? heading?)]
|
||||||
page-name (if heading?
|
(if (and sidebar? (empty? raw-page-headings))
|
||||||
|
(do
|
||||||
|
(state/sidebar-remove-block! (:sidebar/idx option))
|
||||||
|
[:div "Deleted"])
|
||||||
|
(let [page-name (if heading?
|
||||||
(:page/name (db/entity repo (:db/id (:heading/page (first raw-page-headings)))))
|
(:page/name (db/entity repo (:db/id (:heading/page (first raw-page-headings)))))
|
||||||
page-name)
|
page-name)
|
||||||
page (db/entity repo [:page/name page-name])
|
page (db/entity repo [:page/name page-name])
|
||||||
|
@ -155,7 +159,7 @@
|
||||||
|
|
||||||
;; referenced headings
|
;; referenced headings
|
||||||
(when-not sidebar?
|
(when-not sidebar?
|
||||||
(reference/references page-name))]))
|
(reference/references page-name))]))))
|
||||||
|
|
||||||
(rum/defc all-pages < rum/reactive
|
(rum/defc all-pages < rum/reactive
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -14,24 +14,25 @@
|
||||||
[clojure.string :as string]))
|
[clojure.string :as string]))
|
||||||
|
|
||||||
(rum/defc heading-cp < rum/reactive
|
(rum/defc heading-cp < rum/reactive
|
||||||
[repo heading]
|
[repo idx heading]
|
||||||
(let [id (:heading/uuid heading)]
|
(let [id (:heading/uuid heading)]
|
||||||
(page/page {:parameters {:path {:name (str id)}}
|
(page/page {:parameters {:path {:name (str id)}}
|
||||||
:sidebar? true
|
:sidebar? true
|
||||||
|
:sidebar/idx idx
|
||||||
:repo repo})))
|
:repo repo})))
|
||||||
|
|
||||||
(defn build-sidebar-item
|
(defn build-sidebar-item
|
||||||
[repo db-id block-type block-data]
|
[repo idx db-id block-type block-data]
|
||||||
(case block-type
|
(case block-type
|
||||||
:heading-ref
|
:heading-ref
|
||||||
["Block reference"
|
["Block reference"
|
||||||
[:div.ml-2
|
[:div.ml-2
|
||||||
(heading-cp repo (:heading block-data))]]
|
(heading-cp repo idx (:heading block-data))]]
|
||||||
|
|
||||||
:heading
|
:heading
|
||||||
["Block"
|
["Block"
|
||||||
[:div.ml-2
|
[:div.ml-2
|
||||||
(heading-cp repo block-data)]]
|
(heading-cp repo idx block-data)]]
|
||||||
|
|
||||||
:page
|
:page
|
||||||
(let [page-name (get-in block-data [:page :page/name])]
|
(let [page-name (get-in block-data [:page :page/name])]
|
||||||
|
@ -45,7 +46,7 @@
|
||||||
[repo idx db-id block-type block-data]
|
[repo idx db-id block-type block-data]
|
||||||
(let [collapse? (state/sub [:ui/sidebar-collapsed-blocks db-id])]
|
(let [collapse? (state/sub [:ui/sidebar-collapsed-blocks db-id])]
|
||||||
[:div.sidebar-item.content
|
[:div.sidebar-item.content
|
||||||
(let [[title component] (build-sidebar-item repo db-id block-type block-data)]
|
(let [[title component] (build-sidebar-item repo idx db-id block-type block-data)]
|
||||||
[:div.flex.flex-col
|
[:div.flex.flex-col
|
||||||
[:div.flex.flex-row.justify-between
|
[:div.flex.flex-row.justify-between
|
||||||
[:div.flex.flex-row.justify-center
|
[:div.flex.flex-row.justify-center
|
||||||
|
@ -86,7 +87,6 @@
|
||||||
(vis/new-network "page-graph" graph))
|
(vis/new-network "page-graph" graph))
|
||||||
state)
|
state)
|
||||||
|
|
||||||
|
|
||||||
(defonce *show-graph? (atom false))
|
(defonce *show-graph? (atom false))
|
||||||
(rum/defc graph < rum/reactive
|
(rum/defc graph < rum/reactive
|
||||||
{:did-mount render-graph
|
{:did-mount render-graph
|
||||||
|
|
|
@ -236,9 +236,12 @@
|
||||||
(pull (state/get-current-repo) selector eid))
|
(pull (state/get-current-repo) selector eid))
|
||||||
([repo selector eid]
|
([repo selector eid]
|
||||||
(when-let [conn (get-conn repo)]
|
(when-let [conn (get-conn repo)]
|
||||||
|
(try
|
||||||
(d/pull conn
|
(d/pull conn
|
||||||
selector
|
selector
|
||||||
eid))))
|
eid)
|
||||||
|
(catch js/Error e
|
||||||
|
nil)))))
|
||||||
|
|
||||||
(defn pull-many
|
(defn pull-many
|
||||||
([eids]
|
([eids]
|
||||||
|
@ -276,8 +279,7 @@
|
||||||
[:page/ref-pages page-id]
|
[:page/ref-pages page-id]
|
||||||
[:page/ref-pages current-page-id]
|
[:page/ref-pages current-page-id]
|
||||||
[:page/refed-headings current-page-id]
|
[:page/refed-headings current-page-id]
|
||||||
[:page/mentioned-pages current-page-id]
|
[:page/mentioned-pages current-page-id]]
|
||||||
]
|
|
||||||
|
|
||||||
;; refed-pages
|
;; refed-pages
|
||||||
(apply concat
|
(apply concat
|
||||||
|
|
|
@ -914,6 +914,7 @@
|
||||||
([heading value]
|
([heading value]
|
||||||
(insert-new-heading! heading value true))
|
(insert-new-heading! heading value true))
|
||||||
([{:heading/keys [uuid content meta file dummy? level repo] :as heading} value create-new-heading?]
|
([{:heading/keys [uuid content meta file dummy? level repo] :as heading} value create-new-heading?]
|
||||||
|
(when-not dummy?
|
||||||
(let [repo (or repo (state/get-current-repo))
|
(let [repo (or repo (state/get-current-repo))
|
||||||
value (string/trim value)
|
value (string/trim value)
|
||||||
heading (with-heading-meta repo heading)
|
heading (with-heading-meta repo heading)
|
||||||
|
@ -940,7 +941,7 @@
|
||||||
:data headings}
|
:data headings}
|
||||||
file-path
|
file-path
|
||||||
new-content)
|
new-content)
|
||||||
[first-heading last-heading new-heading-content]))))
|
[first-heading last-heading new-heading-content])))))
|
||||||
|
|
||||||
;; TODO: utf8 encode performance
|
;; TODO: utf8 encode performance
|
||||||
(defn check
|
(defn check
|
||||||
|
@ -957,8 +958,9 @@
|
||||||
[{:heading/keys [uuid meta content file repo] :as heading} dummy?]
|
[{:heading/keys [uuid meta content file repo] :as heading} dummy?]
|
||||||
(when-not dummy?
|
(when-not dummy?
|
||||||
(let [repo (or repo (state/get-current-repo))
|
(let [repo (or repo (state/get-current-repo))
|
||||||
heading (db/pull repo '[*] [:heading/uuid uuid])
|
heading (db/pull repo '[*] [:heading/uuid uuid])]
|
||||||
file-path (:file/path (db/entity repo (:db/id file)))
|
(when heading
|
||||||
|
(let [file-path (:file/path (db/entity repo (:db/id file)))
|
||||||
file-content (db/get-file repo file-path)
|
file-content (db/get-file repo file-path)
|
||||||
after-headings (rebuild-after-headings repo file (:end-pos meta) (:pos meta))
|
after-headings (rebuild-after-headings repo file (:end-pos meta) (:pos meta))
|
||||||
new-content (utf8/delete! file-content (:pos meta) (:end-pos meta))]
|
new-content (utf8/delete! file-content (:pos meta) (:end-pos meta))]
|
||||||
|
@ -970,7 +972,7 @@
|
||||||
{:key :heading/change
|
{:key :heading/change
|
||||||
:data [heading]}
|
:data [heading]}
|
||||||
file-path
|
file-path
|
||||||
new-content))))
|
new-content))))))
|
||||||
|
|
||||||
(defn delete-headings!
|
(defn delete-headings!
|
||||||
[repo heading-uuids]
|
[repo heading-uuids]
|
||||||
|
|
|
@ -278,7 +278,8 @@
|
||||||
(when db-id
|
(when db-id
|
||||||
(update-state! :sidebar/blocks (fn [blocks]
|
(update-state! :sidebar/blocks (fn [blocks]
|
||||||
(->> (remove #(= (first %) db-id) blocks)
|
(->> (remove #(= (first %) db-id) blocks)
|
||||||
(cons [repo db-id block-type block-data]))))))
|
(cons [repo db-id block-type block-data])
|
||||||
|
(distinct))))))
|
||||||
(defn sidebar-remove-block!
|
(defn sidebar-remove-block!
|
||||||
[idx]
|
[idx]
|
||||||
(update-state! :sidebar/blocks #(util/drop-nth idx %)))
|
(update-state! :sidebar/blocks #(util/drop-nth idx %)))
|
||||||
|
|
Loading…
Reference in New Issue