fix: whiteboard files not saved

This commit is contained in:
Tienson Qin
2023-12-28 20:16:58 +08:00
parent 580763844b
commit e45eb85633
4 changed files with 10 additions and 4 deletions

View File

@@ -248,6 +248,7 @@
(transact
[_this repo tx-data tx-meta context]
(when repo (state/set-db-latest-tx-time! repo))
(when-let [conn (state/get-datascript-conn repo)]
(try
(let [tx-data (edn/read-string tx-data)

View File

@@ -56,7 +56,7 @@
[repo conn page-db-id outliner-op context]
(let [page-block (d/pull @conn '[*] page-db-id)
page-db-id (:db/id page-block)
whiteboard? (contains? (:block/type page-block) "whiteboard")
whiteboard? (contains? (set (:block/type page-block)) "whiteboard")
blocks-count (ldb/get-page-blocks-count @conn page-db-id)
blocks-just-deleted? (and (zero? blocks-count)
(contains? #{:delete-blocks :move-blocks} outliner-op))]
@@ -69,7 +69,8 @@
blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
(when-not (and (= 1 (count blocks))
(string/blank? (:block/content (first blocks)))
(nil? (:block/file page-block)))
(nil? (:block/file page-block))
(not whiteboard?))
(let [tree-or-blocks (if whiteboard? blocks
(otree/blocks->vec-tree repo @conn blocks (:block/name page-block)))]
(if page-block

View File

@@ -142,7 +142,7 @@
file-db-id (-> page-block :block/file :db/id)
file-path (-> (d/entity db file-db-id) :file/path)]
(if (and (string? file-path) (not-empty file-path))
(let [new-content (if (contains? (:block/type page-block) "whiteboard")
(let [new-content (if (contains? (set (:block/type page-block)) "whiteboard")
(->
(wfu/ugly-pr-str {:blocks tree
:pages (list (remove-transit-ids page-block))})

View File

@@ -31,13 +31,17 @@
[repo & {:keys [diff]
:or {diff 1000}}]
(when repo
(let [last-input-time (get @(get @*state :db/latest-transact-time) repo)]
(let [last-input-time (get-in @*state [:db/latest-transact-time repo])]
(or
(nil? last-input-time)
(let [now (worker-util/time-ms)]
(>= (- now last-input-time) diff))))))
(defn set-db-latest-tx-time!
[repo]
(swap! *state assoc-in [:db/latest-transact-time repo] (worker-util/time-ms)))
(defn get-context
[]
(:worker/context @*state))