Fix deleting issue

pull/645/head
Tienson Qin 2020-06-06 21:52:33 +08:00
parent 58c23413e8
commit a4133956c4
6 changed files with 143 additions and 134 deletions

View File

@ -694,7 +694,7 @@
(state/add-custom-query-component! query (:rum/react-component state)))
state)}
[config options content]
[:div.custom-query.my-2
[:div.custom-query.my-4
[:code (or (:query-title options)
"Query result: ")]
(let [result (db/custom-query content)]
@ -833,7 +833,7 @@
(if (:group-by-page? config)
(for [[page headings] headings]
(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)
(headings-cp headings config)]))
(headings-cp headings config))]))

View File

@ -48,8 +48,12 @@
heading? (util/uuid-string? page-name)
heading-id (and heading? (uuid page-name))
sidebar? (:sidebar? option)
raw-page-headings (get-headings repo page-name journal? heading?)
page-name (if heading?
raw-page-headings (get-headings repo page-name journal? 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)
page (db/entity repo [:page/name page-name])
@ -155,7 +159,7 @@
;; referenced headings
(when-not sidebar?
(reference/references page-name))]))
(reference/references page-name))]))))
(rum/defc all-pages < rum/reactive
[]

View File

@ -14,24 +14,25 @@
[clojure.string :as string]))
(rum/defc heading-cp < rum/reactive
[repo heading]
[repo idx heading]
(let [id (:heading/uuid heading)]
(page/page {:parameters {:path {:name (str id)}}
:sidebar? true
:sidebar/idx idx
:repo repo})))
(defn build-sidebar-item
[repo db-id block-type block-data]
[repo idx db-id block-type block-data]
(case block-type
:heading-ref
["Block reference"
[:div.ml-2
(heading-cp repo (:heading block-data))]]
(heading-cp repo idx (:heading block-data))]]
:heading
["Block"
[:div.ml-2
(heading-cp repo block-data)]]
(heading-cp repo idx block-data)]]
:page
(let [page-name (get-in block-data [:page :page/name])]
@ -45,7 +46,7 @@
[repo idx db-id block-type block-data]
(let [collapse? (state/sub [:ui/sidebar-collapsed-blocks db-id])]
[: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-row.justify-between
[:div.flex.flex-row.justify-center
@ -86,7 +87,6 @@
(vis/new-network "page-graph" graph))
state)
(defonce *show-graph? (atom false))
(rum/defc graph < rum/reactive
{:did-mount render-graph

View File

@ -236,9 +236,12 @@
(pull (state/get-current-repo) selector eid))
([repo selector eid]
(when-let [conn (get-conn repo)]
(try
(d/pull conn
selector
eid))))
eid)
(catch js/Error e
nil)))))
(defn pull-many
([eids]
@ -276,8 +279,7 @@
[:page/ref-pages page-id]
[:page/ref-pages current-page-id]
[:page/refed-headings current-page-id]
[:page/mentioned-pages current-page-id]
]
[:page/mentioned-pages current-page-id]]
;; refed-pages
(apply concat

View File

@ -914,6 +914,7 @@
([heading value]
(insert-new-heading! heading value true))
([{: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))
value (string/trim value)
heading (with-heading-meta repo heading)
@ -940,7 +941,7 @@
:data headings}
file-path
new-content)
[first-heading last-heading new-heading-content]))))
[first-heading last-heading new-heading-content])))))
;; TODO: utf8 encode performance
(defn check
@ -957,8 +958,9 @@
[{:heading/keys [uuid meta content file repo] :as heading} dummy?]
(when-not dummy?
(let [repo (or repo (state/get-current-repo))
heading (db/pull repo '[*] [:heading/uuid uuid])
file-path (:file/path (db/entity repo (:db/id file)))
heading (db/pull repo '[*] [:heading/uuid uuid])]
(when heading
(let [file-path (:file/path (db/entity repo (:db/id file)))
file-content (db/get-file repo file-path)
after-headings (rebuild-after-headings repo file (:end-pos meta) (:pos meta))
new-content (utf8/delete! file-content (:pos meta) (:end-pos meta))]
@ -970,7 +972,7 @@
{:key :heading/change
:data [heading]}
file-path
new-content))))
new-content))))))
(defn delete-headings!
[repo heading-uuids]

View File

@ -278,7 +278,8 @@
(when db-id
(update-state! :sidebar/blocks (fn [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!
[idx]
(update-state! :sidebar/blocks #(util/drop-nth idx %)))