Skip to content

Commit

Permalink
fix: history replace
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc authored and logseq-cldwalker committed Mar 13, 2023
1 parent a345f43 commit acd41f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/frontend/extensions/tldraw.cljs
Expand Up @@ -152,8 +152,8 @@
(tldraw {:renderers tldraw-renderers
:handlers (get-tldraw-handlers page-name)
:onMount on-mount
:onPersist (fn [app _info]
:onPersist (fn [app info]
(state/set-state! [:whiteboard/last-persisted-at (state/get-current-repo)] (util/time-ms))
(util/profile "tldraw persist"
(whiteboard-handler/transact-tldr-delta! page-name app)))
(whiteboard-handler/transact-tldr-delta! page-name app (.-replace info))))
:model data})])))
8 changes: 4 additions & 4 deletions src/main/frontend/handler/whiteboard.cljs
Expand Up @@ -83,7 +83,7 @@
(util/time-ms))}))

(defn- compute-tx
[^js app ^js tl-page new-id-nonces db-id-nonces page-name]
[^js app ^js tl-page new-id-nonces db-id-nonces page-name transact?]
(let [assets (js->clj-keywordize (.getCleanUpAssets app))
new-shapes (.-shapes tl-page)
shapes-index (map #(gobj/get % "id") new-shapes)
Expand Down Expand Up @@ -119,15 +119,15 @@
(map #(shape->block % page-name))
(map with-timestamps))
:delete-blocks deleted-shapes-tx
:metadata {:whiteboard/transact? true
:metadata {:whiteboard/transact? transact?
:data {:page-name page-name
:deleted-shapes deleted-shapes
:new-shapes created-shapes
:changed-shapes changed-shapes
:prev-changed-blocks prev-changed-blocks}}}))

(defonce *last-shapes-nonce (atom {}))
(defn transact-tldr-delta! [page-name ^js app]
(defn transact-tldr-delta! [page-name ^js app replace?]
(let [tl-page ^js (second (first (.-pages app)))
shapes (.-shapes ^js tl-page)
new-id-nonces (set (map (fn [shape]
Expand All @@ -139,7 +139,7 @@
(set (->> (model/get-whiteboard-id-nonces repo page-name)
(map #(update % :id str)))))
{:keys [page-block upserted-blocks delete-blocks metadata]}
(compute-tx app tl-page new-id-nonces db-id-nonces page-name)
(compute-tx app tl-page new-id-nonces db-id-nonces page-name (not replace?))
tx-data (concat delete-blocks [page-block] upserted-blocks)
new-shapes (get-in metadata [:data :new-shapes])
metadata' (cond
Expand Down
2 changes: 1 addition & 1 deletion tldraw/packages/core/src/lib/TLHistory.ts
Expand Up @@ -33,7 +33,7 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
@action persist = (replace = false) => {
if (this.isPaused || this.creating) return
this.app.pages.forEach(page => page.bump()) // Is it ok here?
this.app.notify('persist', null)
this.app.notify('persist', {replace})
}

@action undo = () => {
Expand Down
2 changes: 1 addition & 1 deletion tldraw/packages/core/src/types/types.ts
Expand Up @@ -155,7 +155,7 @@ export type TLSubscriptionEvent =
}
| {
event: 'persist'
info: null
info: { replace: boolean }
}
| {
event: 'save'
Expand Down

0 comments on commit acd41f7

Please sign in to comment.