fix: whiteboard saving timing delay

This commit is contained in:
Peng Xiao
2022-09-24 15:32:41 +08:00
parent 5f8385b098
commit c17c9af067
2 changed files with 18 additions and 10 deletions

View File

@@ -47,7 +47,7 @@
(if (or (and (> blocks-count 500)
(not (state/input-idle? repo {:diff 3000}))) ;; long page
;; when this whiteboard page is just being updated
(and whiteboard? (not (state/whiteboard-page-idle? repo page-block {:diff 3000}))))
(and whiteboard? (not (state/whiteboard-page-idle? repo page-block))))
(async/put! (state/get-file-write-chan) [repo page-db-id])
(let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
blocks (model/get-page-blocks-no-cache repo (:block/name page-block) {:pull-keys pull-keys})

View File

@@ -1466,16 +1466,24 @@ Similar to re-frame subscriptions"
(not (get-edit-input-id)))))
(defn whiteboard-page-idle?
[repo whiteboard-page & {:keys [diff]
:or {diff 1000}}]
"Check if whiteboard page is idle.
- when current tool is select and idle
- and whiteboard page is updated longer than 1000 seconds
- when current tool is other tool and idle
- and whiteboard page is updated longer than 3000 seconds"
[repo whiteboard-page & {:keys [select-idle-ms tool-idle-ms]
:or {select-idle-ms 1000
tool-idle-ms 3000}}]
(when repo
(or
(when-let [last-time (:block/updated-at whiteboard-page)]
(let [now (util/time-ms)]
(>= (- now last-time) diff)))
;; in idle mode
(when-let [tldraw-app (active-tldraw-app)]
(.. tldraw-app (isIn "select.idle"))))))
(if-let [tldraw-app (active-tldraw-app)]
(let [last-time (:block/updated-at whiteboard-page)
now (util/time-ms)
ellapsed (- now last-time)
select-idle (.. tldraw-app (isIn "select.idle"))
tool-idle (.. tldraw-app -selectedTool (isIn "idle"))]
(or (and select-idle (>= ellapsed select-idle-ms))
(and (not select-idle) tool-idle (>= ellapsed tool-idle-ms))))
true)))
(defn set-nfs-refreshing!
[value]