From ed767d9a5b93216c85543a15223bf6ab983e59bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 22 Oct 2025 16:38:49 +0200 Subject: [PATCH] :bug: Fix library update notificacions showing when they should not --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 54 ++++++++++--------- .../app/main/data/workspace/libraries.cljs | 15 +++--- .../main/data/workspace/notifications.cljs | 2 +- frontend/src/app/main/refs.cljs | 3 ++ 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4a761f8423..9ae80438ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -67,6 +67,7 @@ - Fix nested variant in a component doesn't keep inherited overrides [Taiga #12299](https://tree.taiga.io/project/penpot/issue/12299) - Fix selected colors not showing colors from children shapes in multiple selection [Taiga #12384](https://tree.taiga.io/project/penpot/issue/12385) - Fix scrollbar issue in design tab [Taiga #12367](https://tree.taiga.io/project/penpot/issue/12367) +- Fix library update notificacions showing when they should not [Taiga #12397](https://tree.taiga.io/project/penpot/issue/12397) ## 2.10.1 diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 698bafd7b2..d32d9b0439 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -139,9 +139,9 @@ (fn [data] (assoc file :data (d/removem (comp t/pointer? val) data)))))) -(defn- check-libraries-synchronozation +(defn- check-libraries-synchronization [file-id libraries] - (ptk/reify ::check-libraries-synchronozation + (ptk/reify ::check-libraries-synchronization ptk/WatchEvent (watch [_ state _] (let [file (dsh/lookup-file state file-id) @@ -154,7 +154,7 @@ libraries)] (when needs-check? - (->> (rx/of (dwl/notify-sync-file file-id)) + (->> (rx/of (dwl/notify-sync-file)) (rx/delay 1000))))))) (defn- library-resolved @@ -168,30 +168,32 @@ [file-id features] (ptk/reify ::fetch-libries ptk/WatchEvent - (watch [_ _ _] - (rx/concat - (->> (rp/cmd! :get-file-libraries {:file-id file-id}) - (rx/mapcat - (fn [libraries] - (rx/concat - (rx/of (dwl/libraries-fetched file-id libraries)) - (rx/merge - (->> (rx/from libraries) - (rx/merge-map - (fn [{:keys [id synced-at]}] - (->> (rp/cmd! :get-file {:id id :features features}) - (rx/map #(assoc % :synced-at synced-at :library-of file-id))))) - (rx/mapcat resolve-file) - (rx/map library-resolved)) - (->> (rx/from libraries) - (rx/map :id) - (rx/mapcat (fn [file-id] - (rp/cmd! :get-file-object-thumbnails {:file-id file-id :tag "component"}))) - (rx/map dwl/library-thumbnails-fetched))) - (rx/of (check-libraries-synchronozation file-id libraries)))))) + (watch [_ _ stream] + (let [stopper-s (rx/filter (ptk/type? ::finalize-workspace) stream)] + (->> (rx/concat + (->> (rp/cmd! :get-file-libraries {:file-id file-id}) + (rx/mapcat + (fn [libraries] + (rx/concat + (rx/of (dwl/libraries-fetched file-id libraries)) + (rx/merge + (->> (rx/from libraries) + (rx/merge-map + (fn [{:keys [id synced-at]}] + (->> (rp/cmd! :get-file {:id id :features features}) + (rx/map #(assoc % :synced-at synced-at :library-of file-id))))) + (rx/mapcat resolve-file) + (rx/map library-resolved)) + (->> (rx/from libraries) + (rx/map :id) + (rx/mapcat (fn [file-id] + (rp/cmd! :get-file-object-thumbnails {:file-id file-id :tag "component"}))) + (rx/map dwl/library-thumbnails-fetched))) + (rx/of (check-libraries-synchronization file-id libraries)))))) - ;; This events marks that all the libraries have been resolved - (rx/of (ptk/data-event ::all-libraries-resolved)))))) + ;; This events marks that all the libraries have been resolved + (rx/of (ptk/data-event ::all-libraries-resolved))) + (rx/take-until stopper-s)))))) (defn- workspace-initialized [file-id] diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 597518eeac..1ad85bd56a 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1193,19 +1193,22 @@ (ctf/used-assets-changed-since file-data library sync-date)))))) (defn notify-sync-file - ;; file-id is the id of the modified library - [file-id] - (dm/assert! (uuid? file-id)) + "Notify the user that there are updates in the libraries used by the + current file, and ask if he wants to update them now." + [] (ptk/reify ::notify-sync-file ptk/WatchEvent (watch [_ state _] - (let [file (dsh/lookup-file state (:current-file-id state)) + (let [file-id (:current-file-id state) + file (dsh/lookup-file state file-id) file-data (get file :data) ignore-until (get file :ignore-sync-until) libraries-need-sync - (filter #(seq (assets-need-sync % file-data ignore-until)) - (vals (get state :files))) + (->> (vals (get state :files)) + (filter #(= (:library-of %) file-id)) + (filter #(seq (assets-need-sync % file-data ignore-until)))) + do-more-info #(modal/show! :libraries-dialog {:starting-tab "updates" :file-id file-id}) diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index 1f678dd197..9bfc7ac8a2 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -331,4 +331,4 @@ (watch [_ state _] (when (contains? (:files state) file-id) (rx/of (dwl/ext-library-changed file-id modified-at revn changes) - (dwl/notify-sync-file file-id)))))) + (dwl/notify-sync-file)))))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 8faa7b9dcc..f699ce20f1 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -84,6 +84,9 @@ (l/derived :shared-files st/state)) (defn select-libraries + "Find between all the given files, those who are libraries of the file-id. + Also include the file-id file itself. + Return a map of id -> library." [files file-id] (persistent! (reduce-kv (fn [result id file]