mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 11:38:24 -05:00
🐛 Fix race condition issues on workspace.
This commit is contained in:
parent
a3016b8400
commit
384f0a05c6
7 changed files with 58 additions and 45 deletions
|
@ -266,12 +266,10 @@
|
||||||
(ptk/reify ::finalize-page
|
(ptk/reify ::finalize-page
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (or page-id (get-in state [:workspace-data :pages 0]))
|
(let [local (-> (:workspace-local state)
|
||||||
local (-> (:workspace-local state)
|
(dissoc :edition
|
||||||
(dissoc
|
:edit-path
|
||||||
:edition
|
:selected))]
|
||||||
:edit-path
|
|
||||||
:selected))]
|
|
||||||
(-> state
|
(-> state
|
||||||
(assoc-in [:workspace-cache page-id] local)
|
(assoc-in [:workspace-cache page-id] local)
|
||||||
(dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing))))))
|
(dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing))))))
|
||||||
|
@ -348,8 +346,7 @@
|
||||||
(declare purge-page)
|
(declare purge-page)
|
||||||
(declare go-to-file)
|
(declare go-to-file)
|
||||||
|
|
||||||
;; TODO: properly handle positioning on undo.
|
;; TODO: for some reason, the page-id here in some circumstances is `nil`
|
||||||
|
|
||||||
(defn delete-page
|
(defn delete-page
|
||||||
[id]
|
[id]
|
||||||
(ptk/reify ::delete-page
|
(ptk/reify ::delete-page
|
||||||
|
@ -669,6 +666,7 @@
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(rx/of (dch/update-shapes [id] #(merge % attrs))))))
|
(rx/of (dch/update-shapes [id] #(merge % attrs))))))
|
||||||
|
|
||||||
|
|
||||||
(defn start-rename-shape
|
(defn start-rename-shape
|
||||||
[id]
|
[id]
|
||||||
(us/verify ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
|
|
|
@ -114,9 +114,9 @@
|
||||||
:changes changes}))))
|
:changes changes}))))
|
||||||
|
|
||||||
(defn commit-changes
|
(defn commit-changes
|
||||||
[{:keys [redo-changes undo-changes origin save-undo? file-id]
|
[{:keys [redo-changes undo-changes
|
||||||
|
origin save-undo? file-id]
|
||||||
:or {save-undo? true}}]
|
:or {save-undo? true}}]
|
||||||
|
|
||||||
(log/debug :msg "commit-changes"
|
(log/debug :msg "commit-changes"
|
||||||
:js/redo-changes redo-changes
|
:js/redo-changes redo-changes
|
||||||
:js/undo-changes undo-changes)
|
:js/undo-changes undo-changes)
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
(s/def ::set-of-string (s/every string? :kind set?))
|
(s/def ::set-of-string (s/every string? :kind set?))
|
||||||
(s/def ::ordered-set-of-uuid (s/every uuid? :kind d/ordered-set?))
|
(s/def ::ordered-set-of-uuid (s/every uuid? :kind d/ordered-set?))
|
||||||
|
|
||||||
|
(defn initialized?
|
||||||
|
"Check if the state is properly intialized in a workspace. This means
|
||||||
|
it has the `:current-page-id` and `:current-file-id` properly set."
|
||||||
|
[state]
|
||||||
|
(and (uuid? (:current-file-id state))
|
||||||
|
(uuid? (:current-page-id state))))
|
||||||
|
|
||||||
;; --- Helpers
|
;; --- Helpers
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@
|
||||||
|
|
||||||
(defn prepare-remove-group
|
(defn prepare-remove-group
|
||||||
[page-id group objects]
|
[page-id group objects]
|
||||||
(let [shapes (:shapes group)
|
(let [shapes (into [] (:shapes group)) ; ensure we always have vector
|
||||||
parent-id (cp/get-parent (:id group) objects)
|
parent-id (cp/get-parent (:id group) objects)
|
||||||
parent (get objects parent-id)
|
parent (get objects parent-id)
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,14 @@
|
||||||
(rx/filter dch/commit-changes?)
|
(rx/filter dch/commit-changes?)
|
||||||
(rx/debounce 2000)
|
(rx/debounce 2000)
|
||||||
(rx/merge stoper forcer))
|
(rx/merge stoper forcer))
|
||||||
|
local-file?
|
||||||
local-file? #(as-> (:file-id %) event-file-id
|
#(as-> (:file-id %) event-file-id
|
||||||
(or (nil? event-file-id)
|
(or (nil? event-file-id)
|
||||||
(= event-file-id file-id)))
|
(= event-file-id file-id)))
|
||||||
library-file? #(as-> (:file-id %) event-file-id
|
library-file?
|
||||||
(and (some? event-file-id)
|
#(as-> (:file-id %) event-file-id
|
||||||
(not= event-file-id file-id)))
|
(and (some? event-file-id)
|
||||||
|
(not= event-file-id file-id)))
|
||||||
|
|
||||||
on-dirty
|
on-dirty
|
||||||
(fn []
|
(fn []
|
||||||
|
@ -565,6 +566,20 @@
|
||||||
[frame-id]
|
[frame-id]
|
||||||
(ptk/event ::update-frame-thumbnail {:frame-id frame-id}))
|
(ptk/event ::update-frame-thumbnail {:frame-id frame-id}))
|
||||||
|
|
||||||
|
(defn update-shape-thumbnail
|
||||||
|
"An event that is succeptible to be executed out of the main flow, so
|
||||||
|
it need to correctly handle the situation that there are no page-id
|
||||||
|
or file-is loaded."
|
||||||
|
[shape-id thumbnail-data]
|
||||||
|
(ptk/reify ::update-shape-thumbnail
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state _]
|
||||||
|
(when (and (dwc/initialized? state)
|
||||||
|
(uuid? shape-id))
|
||||||
|
(rx/of (dch/update-shapes [shape-id]
|
||||||
|
#(assoc % :thumbnail thumbnail-data)
|
||||||
|
{:save-undo? false}))))))
|
||||||
|
|
||||||
(defn- extract-frame-changes
|
(defn- extract-frame-changes
|
||||||
"Process a changes set in a commit to extract the frames that are channging"
|
"Process a changes set in a commit to extract the frames that are channging"
|
||||||
[[event [old-objects new-objects]]]
|
[[event [old-objects new-objects]]]
|
||||||
|
|
|
@ -54,23 +54,23 @@
|
||||||
(ptk/reify ::finalize-editor-state
|
(ptk/reify ::finalize-editor-state
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [content (-> (get-in state [:workspace-editor-state id])
|
(when (dwc/initialized? state)
|
||||||
(ted/get-editor-current-content))]
|
(let [content (-> (get-in state [:workspace-editor-state id])
|
||||||
|
(ted/get-editor-current-content))]
|
||||||
|
(if (ted/content-has-text? content)
|
||||||
|
(let [content (d/merge (ted/export-content content)
|
||||||
|
(dissoc (:content shape) :children))]
|
||||||
|
(rx/merge
|
||||||
|
(rx/of (update-editor-state shape nil))
|
||||||
|
(when (and (not= content (:content shape))
|
||||||
|
(some? (:current-page-id state)))
|
||||||
|
(rx/of
|
||||||
|
(dch/update-shapes [id] #(assoc % :content content))
|
||||||
|
(dwu/commit-undo-transaction)))))
|
||||||
|
|
||||||
(if (ted/content-has-text? content)
|
(when (some? id)
|
||||||
(let [content (d/merge (ted/export-content content)
|
(rx/of (dws/deselect-shape id)
|
||||||
(dissoc (:content shape) :children))]
|
(dwc/delete-shapes #{id})))))))))
|
||||||
(rx/merge
|
|
||||||
(rx/of (update-editor-state shape nil))
|
|
||||||
(when (and (not= content (:content shape))
|
|
||||||
(some? (:current-page-id state)))
|
|
||||||
(rx/of
|
|
||||||
(dch/update-shapes [id] #(assoc % :content content))
|
|
||||||
(dwu/commit-undo-transaction)))))
|
|
||||||
|
|
||||||
(when (some? id)
|
|
||||||
(rx/of (dws/deselect-shape id)
|
|
||||||
(dwc/delete-shapes #{id}))))))))
|
|
||||||
|
|
||||||
(defn initialize-editor-state
|
(defn initialize-editor-state
|
||||||
[{:keys [id content] :as shape} decorator]
|
[{:keys [id content] :as shape} decorator]
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
(ns app.main.ui.workspace.viewport.thumbnail-renderer
|
(ns app.main.ui.workspace.viewport.thumbnail-renderer
|
||||||
(:require
|
(:require
|
||||||
[app.main.data.workspace.changes :as dwc]
|
|
||||||
[app.main.data.workspace.persistence :as dwp]
|
[app.main.data.workspace.persistence :as dwp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
@ -80,7 +79,7 @@
|
||||||
"Component in charge of creating thumbnails and storing them"
|
"Component in charge of creating thumbnails and storing them"
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [objects (obj/get props "objects")
|
(let [objects (obj/get props "objects")
|
||||||
background (obj/get props "background")
|
background (obj/get props "background")
|
||||||
|
|
||||||
;; Id of the current frame being rendered
|
;; Id of the current frame being rendered
|
||||||
|
@ -97,12 +96,9 @@
|
||||||
|
|
||||||
updates-stream
|
updates-stream
|
||||||
(mf/use-memo
|
(mf/use-memo
|
||||||
(fn []
|
#(let [update-events (rx/filter dwp/update-frame-thumbnail? st/stream)]
|
||||||
(let [update-events
|
(->> (rx/zip update-events next)
|
||||||
(->> st/stream
|
(rx/map first))))
|
||||||
(rx/filter dwp/update-frame-thumbnail?))]
|
|
||||||
(->> (rx/zip update-events next)
|
|
||||||
(rx/map first)))))
|
|
||||||
|
|
||||||
on-thumbnail-data
|
on-thumbnail-data
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
|
@ -111,9 +107,7 @@
|
||||||
(reset! shape-id nil)
|
(reset! shape-id nil)
|
||||||
(timers/schedule
|
(timers/schedule
|
||||||
(fn []
|
(fn []
|
||||||
(st/emit! (dwc/update-shapes [@shape-id]
|
(st/emit! (dwp/update-shape-thumbnail @shape-id data))
|
||||||
#(assoc % :thumbnail data)
|
|
||||||
{:save-undo? false}))
|
|
||||||
(rx/push! next :next)))))
|
(rx/push! next :next)))))
|
||||||
|
|
||||||
on-frame-not-found
|
on-frame-not-found
|
||||||
|
|
Loading…
Add table
Reference in a new issue