diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index d219fc365c..b0ab2b5bd5 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -732,7 +732,8 @@ :main-instance-id (:main-instance-id new-component) :main-instance-page (:main-instance-page new-component) :annotation (:annotation new-component) - :objects (:objects new-component)}) ;; this won't exist in components-v2 (except for deleted components) + :objects (:objects new-component) ;; this won't exist in components-v2 (except for deleted components) + :modified-at (:modified-at new-component)}) (update :undo-changes conj {:type :mod-component :id id :name (:name prev-component) diff --git a/common/src/app/common/types/components_list.cljc b/common/src/app/common/types/components_list.cljc index 1eefe30216..8165c2d232 100644 --- a/common/src/app/common/types/components_list.cljc +++ b/common/src/app/common/types/components_list.cljc @@ -48,7 +48,7 @@ (wrap-object-fn))))))) (defn mod-component - [file-data {:keys [id name path main-instance-id main-instance-page objects annotation]}] + [file-data {:keys [id name path main-instance-id main-instance-page objects annotation modified-at]}] (let [wrap-objects-fn cfeat/*wrap-with-objects-map-fn*] (d/update-in-when file-data [:components id] (fn [component] @@ -69,6 +69,9 @@ (some? objects) (assoc :objects objects) + (some? modified-at) + (assoc :modified-at modified-at) + (some? annotation) (assoc :annotation annotation) @@ -76,7 +79,7 @@ (dissoc :annotation)) diff (set/difference (ctk/diff-components component new-comp) - #{:annotation})] ;; The set of properties that doesn't mark a component as touched + #{:annotation :modified-at})] ;; The set of properties that doesn't mark a component as touched (if (empty? diff) new-comp diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 2f0961b784..e9ea4ee5e7 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -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