|
|
@@ -10,7 +10,10 @@
|
|
|
[promesa.core :as p]
|
|
|
[frontend.persist-db :as persist-db]
|
|
|
[clojure.string :as string]
|
|
|
- [datascript.core :as d]))
|
|
|
+ [datascript.core :as d]
|
|
|
+ [frontend.handler.file-based.property.util :as property-util]
|
|
|
+ [frontend.util.drawer :as drawer]
|
|
|
+ [frontend.util.cursor :as cursor]))
|
|
|
|
|
|
(defn updated-page-hook
|
|
|
[tx-report page]
|
|
|
@@ -26,19 +29,26 @@
|
|
|
|
|
|
(defn- reset-editing-block-content!
|
|
|
[tx-data]
|
|
|
- (let [repo (state/get-current-repo)]
|
|
|
- (when (config/db-based-graph? repo)
|
|
|
- (when-let [edit-block (state/get-edit-block)]
|
|
|
- (when-let [last-datom (-> (filter (fn [datom]
|
|
|
- (and (= :block/content (:a datom))
|
|
|
- (= (:e datom) (:db/id edit-block)))) tx-data)
|
|
|
- last)]
|
|
|
- (when-let [input (state/get-input)]
|
|
|
- (when (:added last-datom)
|
|
|
- (let [db-content (:block/content (db/entity (:e last-datom)))]
|
|
|
- (when (not= (string/trim db-content)
|
|
|
- (string/trim (.-value input)))
|
|
|
- (state/set-edit-content! input db-content))))))))))
|
|
|
+ (let [repo (state/get-current-repo)
|
|
|
+ db? (config/db-based-graph? repo)]
|
|
|
+ (when-let [edit-block (state/get-edit-block)]
|
|
|
+ (when-let [last-datom (-> (filter (fn [datom]
|
|
|
+ (and (= :block/content (:a datom))
|
|
|
+ (= (:e datom) (:db/id edit-block)))) tx-data)
|
|
|
+ last)]
|
|
|
+ (when-let [input (state/get-input)]
|
|
|
+ (when (:added last-datom)
|
|
|
+ (let [entity (db/entity (:e last-datom))
|
|
|
+ db-content (:block/content entity)
|
|
|
+ content (if db? db-content
|
|
|
+ (->> db-content
|
|
|
+ (property-util/remove-built-in-properties (or (:block/format entity) :markdown))
|
|
|
+ drawer/remove-logbook))
|
|
|
+ pos (cursor/pos input)]
|
|
|
+ (when (not= (string/trim content)
|
|
|
+ (string/trim (.-value input)))
|
|
|
+ (state/set-edit-content! input content)
|
|
|
+ (when pos (cursor/move-cursor-to input pos))))))))))
|
|
|
|
|
|
(defn- delete-property-parent-block-if-empty!
|
|
|
[repo tx-report deleted-block-uuids]
|
|
|
@@ -94,7 +104,7 @@
|
|
|
(when-not importing?
|
|
|
(react/refresh! repo tx-report'))
|
|
|
|
|
|
- (when (and (config/db-based-graph? repo) (not (:skip-persist? tx-meta))
|
|
|
+ (when (and (not (:skip-persist? tx-meta))
|
|
|
(not replace?)
|
|
|
(not (:update-tx-ids? tx-meta)))
|
|
|
(let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report'))
|
|
|
@@ -107,15 +117,13 @@
|
|
|
(when (seq update-tx-ids)
|
|
|
(db/transact! repo update-tx-ids {:replace? true
|
|
|
:update-tx-ids? true}))
|
|
|
- (when-not config/publishing?
|
|
|
- (p/let [_transact-result (persist-db/<transact-data repo upsert-blocks deleted-block-uuids)
|
|
|
- _ipc-result (comment ipc/ipc :db-transact-data repo
|
|
|
- (pr-str
|
|
|
- {:blocks upsert-blocks
|
|
|
- :deleted-block-uuids deleted-block-uuids}))]
|
|
|
- ;; TODO: disable edit when transact failed to avoid future data-loss
|
|
|
- ;; (prn "DB transact result: " ipc-result)
|
|
|
- ))))
|
|
|
+ (when (config/db-based-graph? repo)
|
|
|
+ (when-not config/publishing?
|
|
|
+ (p/let [_transact-result (persist-db/<transact-data repo upsert-blocks deleted-block-uuids)
|
|
|
+ _ipc-result (comment ipc/ipc :db-transact-data repo
|
|
|
+ (pr-str
|
|
|
+ {:blocks upsert-blocks
|
|
|
+ :deleted-block-uuids deleted-block-uuids}))])))))
|
|
|
|
|
|
(when (and (not (:delete-files? tx-meta))
|
|
|
(not replace?))
|