diff --git a/common/src/app/common/files/libraries_helpers.cljc b/common/src/app/common/files/libraries_helpers.cljc index afec467c8..d700237d2 100644 --- a/common/src/app/common/files/libraries_helpers.cljc +++ b/common/src/app/common/files/libraries_helpers.cljc @@ -2047,6 +2047,30 @@ (generate-new-shape-for-swap shape file page libraries id-new-component index target-cell keep-props-values))] [new-shape all-parents changes])) +(defn generate-sync-file-changes + [changes undo-group asset-type file-id asset-id library-id libraries current-file-id] + (let [sync-components? (or (nil? asset-type) (= asset-type :components)) + sync-colors? (or (nil? asset-type) (= asset-type :colors)) + sync-typographies? (or (nil? asset-type) (= asset-type :typographies))] + (cond-> changes + :always + (pcb/set-undo-group undo-group) + ;; library-changes + sync-components? + (generate-sync-library file-id :components asset-id library-id libraries current-file-id) + sync-colors? + (generate-sync-library file-id :colors asset-id library-id libraries current-file-id) + sync-typographies? + (generate-sync-library file-id :typographies asset-id library-id libraries current-file-id) + + ;; file-changes + sync-components? + (generate-sync-file file-id :components asset-id library-id libraries current-file-id) + sync-colors? + (generate-sync-file file-id :colors asset-id library-id libraries current-file-id) + sync-typographies? + (generate-sync-file file-id :typographies asset-id library-id libraries current-file-id)))) + (defn generate-sync-head [changes file-full libraries container id components-v2 reset?] (let [shape-inst (ctn/get-shape container id) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 5d218e4d9..a542301e8 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -976,34 +976,15 @@ libraries (wsh/get-libraries state) current-file-id (:current-file-id state) - - sync-components? (or (nil? asset-type) (= asset-type :components)) - sync-colors? (or (nil? asset-type) (= asset-type :colors)) - sync-typographies? (or (nil? asset-type) (= asset-type :typographies)) - - library-changes (reduce - pcb/concat-changes - (-> (pcb/empty-changes it) - (pcb/set-undo-group undo-group)) - [(when sync-components? - (cflh/generate-sync-library (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id)) - (when sync-colors? - (cflh/generate-sync-library (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id)) - (when sync-typographies? - (cflh/generate-sync-library (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))]) - - file-changes (reduce - pcb/concat-changes - (-> (pcb/empty-changes it) - (pcb/set-undo-group undo-group)) - [(when sync-components? - (cflh/generate-sync-file (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id)) - (when sync-colors? - (cflh/generate-sync-file (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id)) - (when sync-typographies? - (cflh/generate-sync-file (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))]) - - changes (pcb/concat-changes library-changes file-changes) + changes (cflh/generate-sync-file-changes + (pcb/empty-changes it) + undo-group + asset-type + file-id + asset-id + library-id + libraries + current-file-id) find-frames (fn [change] (->> (ch/frames-changed file change) @@ -1021,8 +1002,7 @@ (rx/of (set-updating-library false) (msg/hide-tag :sync-dialog)) (when (seq (:redo-changes changes)) - (rx/of (dch/commit-changes (assoc changes ;; TODO a ver qué pasa con esto - :file-id file-id)))) + (rx/of (dch/commit-changes changes))) (when-not (empty? updated-frames) (rx/merge (rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group}))