mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 07:16:07 -05:00
Revert "🐛 Fix workspace hot reload race condtion (#5851)"
This reverts commit 5d56d28cb6
.
This commit is contained in:
parent
af93325fd9
commit
8139ee3ef9
6 changed files with 51 additions and 42 deletions
|
@ -460,11 +460,10 @@
|
|||
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [file (dissoc file :data)]
|
||||
(-> state
|
||||
(assoc-in [:files id] file)
|
||||
(assoc-in [:recent-files id] file)
|
||||
(update-in [:projects project-id :count] inc))))))
|
||||
(update-in [:projects project-id :count] inc)))))
|
||||
|
||||
(defn create-file
|
||||
[{:keys [project-id name] :as params}]
|
||||
|
|
|
@ -319,6 +319,8 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(-> state
|
||||
(dissoc :files)
|
||||
(dissoc :workspace-ready)
|
||||
(assoc :recent-colors (:recent-colors storage/user))
|
||||
(assoc :recent-fonts (:recent-fonts storage/user))
|
||||
(assoc :current-file-id file-id)
|
||||
|
@ -393,9 +395,11 @@
|
|||
(dissoc
|
||||
:current-file-id
|
||||
:workspace-editor-state
|
||||
:files
|
||||
:workspace-media-objects
|
||||
:workspace-persistence
|
||||
:workspace-presence
|
||||
:workspace-ready
|
||||
:workspace-undo)
|
||||
(update :workspace-global dissoc :read-only?)
|
||||
(assoc-in [:workspace-global :options-mode] :design)))
|
||||
|
@ -423,18 +427,18 @@
|
|||
(defmethod ptk/resolve ::reload-current-file [_ _] (reload-current-file))
|
||||
|
||||
(defn initialize-page
|
||||
[file-id page-id]
|
||||
(assert (uuid? file-id) "expected valid uuid for `file-id`")
|
||||
[page-id]
|
||||
(assert (uuid? page-id) "expected valid uuid for `page-id`")
|
||||
|
||||
(ptk/reify ::initialize-page
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(if-let [page (dsh/lookup-page state file-id page-id)]
|
||||
(if-let [{:keys [id] :as page} (dsh/lookup-page state page-id)]
|
||||
;; we maintain a cache of page state for user convenience with the exception of the
|
||||
;; selection; when user abandon the current page, the selection is lost
|
||||
(let [local (dm/get-in state [:workspace-cache [file-id page-id]] default-workspace-local)]
|
||||
(let [local (dm/get-in state [:workspace-cache id] default-workspace-local)]
|
||||
(-> state
|
||||
(assoc :current-page-id page-id)
|
||||
(assoc :current-page-id id)
|
||||
(assoc :workspace-local (assoc local :selected (d/ordered-set)))
|
||||
(assoc :workspace-trimmed-page (dm/select-keys page [:id :name]))
|
||||
|
||||
|
@ -446,25 +450,24 @@
|
|||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(if (dsh/lookup-page state file-id page-id)
|
||||
(if (dsh/lookup-page state page-id)
|
||||
(let [file-id (:current-file-id state)]
|
||||
(rx/of (preload-data-uris page-id)
|
||||
(dwth/watch-state-changes file-id page-id)
|
||||
(dwl/watch-component-changes))
|
||||
(rx/of (dcm/go-to-workspace :file-id file-id ::rt/replace true))))))
|
||||
(dwl/watch-component-changes)))
|
||||
(rx/of (dcm/go-to-workspace))))))
|
||||
|
||||
(defn finalize-page
|
||||
[file-id page-id]
|
||||
(assert (uuid? file-id) "expected valid uuid for `file-id`")
|
||||
[page-id]
|
||||
(assert (uuid? page-id) "expected valid uuid for `page-id`")
|
||||
|
||||
(ptk/reify ::finalize-page
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [local (-> (:workspace-local state)
|
||||
(dissoc :edition :edit-path :selected))
|
||||
exit? (not= :workspace (rt/lookup-name state))
|
||||
exit? (not= :workspace (dm/get-in state [:route :data :name]))
|
||||
state (-> state
|
||||
(update :workspace-cache assoc [file-id page-id] local)
|
||||
(update :workspace-cache assoc page-id local)
|
||||
(dissoc :current-page-id
|
||||
:workspace-local
|
||||
:workspace-trimmed-page
|
||||
|
|
|
@ -120,11 +120,6 @@
|
|||
([id params & {:as options}]
|
||||
(navigate id params options)))
|
||||
|
||||
(defn lookup-name
|
||||
[state]
|
||||
(dm/get-in state [:route :data :name]))
|
||||
|
||||
;; FIXME: rename to lookup-params
|
||||
(defn get-params
|
||||
[state]
|
||||
(dm/get-in state [:route :params :query]))
|
||||
|
|
|
@ -127,6 +127,7 @@
|
|||
{::mf/props :obj
|
||||
::mf/private true}
|
||||
[{:keys [team-id children]}]
|
||||
|
||||
(mf/with-effect [team-id]
|
||||
(st/emit! (dtm/initialize-team team-id))
|
||||
(fn []
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.main.data.common :as dcm]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.persistence :as dps]
|
||||
[app.main.data.plugins :as dpl]
|
||||
[app.main.data.workspace :as dw]
|
||||
|
@ -42,6 +43,13 @@
|
|||
[okulary.core :as l]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn- make-workspace-ready-ref
|
||||
[file-id]
|
||||
(l/derived (fn [state]
|
||||
(and (= file-id (:workspace-ready state))
|
||||
(some? (dsh/lookup-file-data state file-id))))
|
||||
st/state))
|
||||
|
||||
(mf/defc workspace-content*
|
||||
{::mf/private true}
|
||||
[{:keys [file layout page wglobal]}]
|
||||
|
@ -130,18 +138,22 @@
|
|||
key (events/listen globals/window "blur" focus-out)]
|
||||
(partial events/unlistenByKey key)))
|
||||
|
||||
(mf/with-effect [file page-id]
|
||||
(st/emit! (dw/initialize-page (:id file) page-id))
|
||||
(mf/with-effect [page-id]
|
||||
(if (some? page-id)
|
||||
(st/emit! (dw/initialize-page page-id))
|
||||
(st/emit! (dcm/go-to-workspace ::rt/replace true)))
|
||||
|
||||
(fn []
|
||||
(when page-id
|
||||
(st/emit! (dw/finalize-page (:id file) page-id)))))
|
||||
(when (some? page-id)
|
||||
(st/emit! (dw/finalize-page page-id)))))
|
||||
|
||||
(if (some? page)
|
||||
[:> workspace-content* {:file file
|
||||
:page page
|
||||
:wglobal wglobal
|
||||
:layout layout}]
|
||||
[:> workspace-loader*])))
|
||||
[:& workspace-loader*])))
|
||||
|
||||
|
||||
(def ^:private ref:file-without-data
|
||||
(l/derived (fn [file]
|
||||
|
@ -169,6 +181,10 @@
|
|||
read-only? (mf/deref refs/workspace-read-only?)
|
||||
read-only? (or read-only? (not (:can-edit permissions)))
|
||||
|
||||
ready* (mf/with-memo [file-id]
|
||||
(make-workspace-ready-ref file-id))
|
||||
ready? (mf/deref ready*)
|
||||
|
||||
design-tokens? (features/use-feature "design-tokens/v1")
|
||||
|
||||
background-color (:background-color wglobal)]
|
||||
|
@ -191,10 +207,6 @@
|
|||
(st/emit! ::dps/force-persist
|
||||
(dw/finalize-workspace file-id))))
|
||||
|
||||
(mf/with-effect [file page-id]
|
||||
(when-not page-id
|
||||
(st/emit! (dcm/go-to-workspace :file-id file-id ::rt/replace true))))
|
||||
|
||||
[:> (mf/provider ctx/current-project-id) {:value project-id}
|
||||
[:> (mf/provider ctx/current-file-id) {:value file-id}
|
||||
[:> (mf/provider ctx/current-page-id) {:value page-id}
|
||||
|
@ -207,9 +219,8 @@
|
|||
:touch-action "none"}}
|
||||
[:> context-menu*]
|
||||
|
||||
(if (some? file)
|
||||
[:> workspace-page*
|
||||
{:page-id page-id
|
||||
(if ^boolean ready?
|
||||
[:> workspace-page* {:page-id page-id
|
||||
:file file
|
||||
:wglobal wglobal
|
||||
:layout layout}]
|
||||
|
|
|
@ -63,10 +63,10 @@
|
|||
target-container-id (or target-container-id (:parent-id shape))]
|
||||
|
||||
(filter some?
|
||||
[(when target-page-id (dw/initialize-page (:id file) target-page-id))
|
||||
[(when target-page-id (dw/initialize-page target-page-id))
|
||||
(dws/select-shape target-container-id)
|
||||
(dw/paste-shapes pdata)
|
||||
(when target-page-id (dw/initialize-page (:id file) (:id page)))])))
|
||||
(when target-page-id (dw/initialize-page (:id page)))])))
|
||||
|
||||
(defn- sync-file [file]
|
||||
(map (fn [component-tag]
|
||||
|
|
Loading…
Add table
Reference in a new issue