🐛 Fix change structure of comp doesn't update copies on another file

This commit is contained in:
Pablo Alba 2024-03-13 21:29:11 +01:00 committed by Andrés Moya
parent d6b60ce43a
commit a5b156e0d6
3 changed files with 39 additions and 9 deletions

View file

@ -1186,6 +1186,26 @@
:callback do-update}]
:tag :sync-dialog)))))))
(defn touch-component
"Update the modified-at attribute of the component to now"
[id]
(dm/verify! (uuid? id))
(ptk/reify ::touch-component
cljs.core/IDeref
(-deref [_] [id])
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/update-component id #(assoc % :modified-at (dt/now))))]
(rx/of (dch/commit-changes {:origin it
:redo-changes (:redo-changes changes)
:undo-changes []
:save-undo? false}))))))
(defn component-changed
"Notify that the component with the given id has changed, so it needs to be updated
in the current file and in the copies. And also update its thumbnails."
@ -1197,6 +1217,7 @@
ptk/WatchEvent
(watch [_ _ _]
(rx/of
(touch-component component-id)
(launch-component-sync component-id file-id undo-group)))))
(defn watch-component-changes
@ -1244,13 +1265,18 @@
(map (partial ch/components-changed old-data))
(reduce into #{})))]
(if (and (d/not-empty? changed-components) save-undo?)
(do (log/info :msg "DETECTED COMPONENTS CHANGED"
:ids (map str changed-components)
:undo-group undo-group)
(if (d/not-empty? changed-components)
(if save-undo?
(do (log/info :msg "DETECTED COMPONENTS CHANGED"
:ids (map str changed-components)
:undo-group undo-group)
(->> (rx/from changed-components)
(rx/map #(component-changed % (:id old-data) undo-group))))
(->> (rx/from changed-components)
(rx/map #(component-changed % (:id old-data) undo-group))))
;; even if save-undo? is false, we need to update the :modified-date of the component
;; (for example, for undos)
(->> (rx/from changed-components)
(rx/map #(touch-component %))))
(rx/empty)))))
changes-s