mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 04:06:14 +02:00
Merge pull request #3290 from penpot/hiru-fix-update-notifications
🐛 Solve error in notification of library changes
This commit is contained in:
commit
498ba257b6
6 changed files with 60 additions and 46 deletions
|
@ -211,8 +211,9 @@
|
|||
(->> (rp/cmd! :get-file-libraries {:file-id id})
|
||||
(rx/mapcat identity)
|
||||
(rx/merge-map
|
||||
(fn [{:keys [id]}]
|
||||
(rp/cmd! :get-file {:id id :features features})))
|
||||
(fn [{:keys [id synced-at]}]
|
||||
(->> (rp/cmd! :get-file {:id id :features features})
|
||||
(rx/map #(assoc % :synced-at synced-at)))))
|
||||
(rx/merge-map
|
||||
(fn [{:keys [id data] :as file}]
|
||||
(->> (resolve-file-data id data)
|
||||
|
@ -231,13 +232,15 @@
|
|||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [file-data (:workspace-data state)
|
||||
(let [file-id (dm/get-in state [:workspace-file :id])
|
||||
ignore-until (dm/get-in state [:workspace-file :ignore-sync-until])
|
||||
file-id (dm/get-in state [:workspace-file :id])
|
||||
needs-update? (seq (filter #(dwl/assets-need-sync % file-data ignore-until)
|
||||
libraries))]
|
||||
(when needs-update?
|
||||
(rx/of (dwl/notify-sync-file file-id)))))))
|
||||
needs-check? (some #(and (> (:modified-at %) (:synced-at %))
|
||||
(or (not ignore-until)
|
||||
(> (:modified-at %) ignore-until)))
|
||||
libraries)]
|
||||
(when needs-check?
|
||||
(rx/concat (rx/timer 1000)
|
||||
(rx/of (dwl/notify-sync-file file-id))))))))
|
||||
|
||||
(defn- fetch-thumbnail-blob-uri
|
||||
[uri]
|
||||
|
|
|
@ -195,6 +195,7 @@
|
|||
(update [_ state]
|
||||
(log/info :msg "commit-changes"
|
||||
:js/undo-group (str undo-group)
|
||||
:js/file-id (str (or file-id "nil"))
|
||||
:js/redo-changes redo-changes
|
||||
:js/undo-changes undo-changes)
|
||||
(let [current-file-id (get state :current-file-id)
|
||||
|
|
|
@ -842,9 +842,9 @@
|
|||
The sequence items are tuples of (page-id shape-id asset-id asset-type)."
|
||||
([library file-data] (assets-need-sync library file-data nil))
|
||||
([library file-data ignore-until]
|
||||
(let [sync-date (max (:synced-at library) (or ignore-until 0))]
|
||||
(when (> (:modified-at library) sync-date)
|
||||
(ctf/used-assets-changed-since file-data library sync-date)))))
|
||||
(let [sync-date (max (:synced-at library) (or ignore-until 0))]
|
||||
(when (> (:modified-at library) sync-date)
|
||||
(ctf/used-assets-changed-since file-data library sync-date)))))
|
||||
|
||||
(defn notify-sync-file
|
||||
[file-id]
|
||||
|
@ -853,7 +853,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [file-data (:workspace-data state)
|
||||
libraries-need-sync (filter #(seq (assets-need-sync % file-data))
|
||||
ignore-until (dm/get-in state [:workspace-file :ignore-sync-until])
|
||||
libraries-need-sync (filter #(seq (assets-need-sync % file-data ignore-until))
|
||||
(vals (get state :workspace-libraries)))
|
||||
do-update #(do (apply st/emit! (map (fn [library]
|
||||
(sync-file (:current-file-id state)
|
||||
|
@ -904,10 +905,15 @@
|
|||
check-changes
|
||||
(fn [[event [old-data _mid_data _new-data]]]
|
||||
(when old-data
|
||||
(let [{:keys [changes save-undo? undo-group]} (deref event)
|
||||
components-changed (reduce #(into %1 (ch/components-changed old-data %2))
|
||||
#{}
|
||||
changes)]
|
||||
(let [{:keys [file-id changes save-undo? undo-group]}
|
||||
(deref event)
|
||||
|
||||
components-changed
|
||||
(when (or (nil? file-id) (= file-id (:id old-data)))
|
||||
(reduce #(into %1 (ch/components-changed old-data %2))
|
||||
#{}
|
||||
changes))]
|
||||
|
||||
(when (and (d/not-empty? components-changed) save-undo?)
|
||||
(log/info :msg "DETECTED COMPONENTS CHANGED"
|
||||
:ids (map str components-changed)
|
||||
|
|
|
@ -234,9 +234,10 @@
|
|||
|
||||
(mf/defc updates-tab
|
||||
{::mf/wrap-props false}
|
||||
[{:keys [file-id libraries]}]
|
||||
(let [libraries (mf/with-memo [libraries]
|
||||
(filter #(> (:modified-at %) (:synced-at %)) (vals libraries)))
|
||||
[{:keys [file-id file-data libraries]}]
|
||||
(let [libraries (mf/with-memo [file-data libraries]
|
||||
(filter #(seq (dwl/assets-need-sync % file-data))
|
||||
(vals libraries)))
|
||||
|
||||
update (mf/use-fn
|
||||
(mf/deps file-id)
|
||||
|
@ -267,6 +268,7 @@
|
|||
::mf/register-as :libraries-dialog}
|
||||
[]
|
||||
(let [project (mf/deref refs/workspace-project)
|
||||
file-data (mf/deref refs/workspace-data)
|
||||
file (mf/deref ref:workspace-file)
|
||||
|
||||
team-id (:team-id project)
|
||||
|
@ -319,5 +321,6 @@
|
|||
:shared-libraries shared-libraries}]
|
||||
:updates
|
||||
[:& updates-tab {:file-id file-id
|
||||
:file-data file-data
|
||||
:libraries libraries}])]]]]))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue