0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

🐛 Fix workspace initialization unexpected behavior.

This commit is contained in:
Andrey Antukh 2020-01-14 21:01:05 +01:00
parent 84df0c431b
commit 747213dea3
4 changed files with 34 additions and 35 deletions

View file

@ -182,13 +182,13 @@
(def workspace-default
{:zoom 1
:flags #{:sitemap :drawtools :layers :element-options :rules}
:flags #{}
:selected #{}
:drawing nil
:drawing-tool nil
:tooltip nil})
(declare initialize-state)
(declare initialize-layout)
(declare initialize-page)
(declare initialize-file)
@ -200,33 +200,30 @@
(ptk/reify ::initialize
ptk/WatchEvent
(watch [_ state stream]
(let [local (:workspace-local state)]
(if (not= (:file-id local) file-id)
(let [file (:workspace-file state)]
(if (not= (:id file) file-id)
(rx/merge
(rx/of (dp/fetch-file file-id)
(dp/fetch-pages file-id)
(initialize-layout file-id)
(fetch-users file-id))
(->> (rx/zip (rx/filter (ptk/type? ::dp/pages-fetched) stream)
(rx/filter (ptk/type? ::dp/files-fetched) stream))
(rx/take 1)
(rx/do #(reset! st/loader false))
(rx/mapcat #(rx/of (initialize-state file-id)
(initialize-file file-id)
(rx/mapcat #(rx/of (initialize-file file-id)
(initialize-page page-id)
#_(initialize-alignment page-id)))))
(rx/of (initialize-file file-id)
(initialize-page page-id)))))))
(defn- initialize-state
(defn- initialize-layout
[file-id]
(us/assert ::us/uuid file-id)
(ptk/reify ::initialize-state
(ptk/reify ::initialize-layout
ptk/UpdateEvent
(update [_ state]
(let [local (assoc workspace-default :file-id file-id)]
(-> state
(assoc :workspace-layout default-layout)
(assoc :workspace-local local))))))
(assoc state :workspace-layout default-layout))))
(defn- initialize-file
[file-id]
@ -245,6 +242,7 @@
(let [page (get-in state [:pages page-id])
data (get-in state [:pages-data page-id])]
(assoc state
:workspace-local workspace-default
:workspace-data data
:workspace-page page)))
@ -1015,6 +1013,13 @@
(def commit-batched-changes
(ptk/reify ::commit-batched-changes
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace-page :id])
data (get-in state [:pages-data pid])
changes (::batched-changes state)]
(update-in state [:pages-data pid] cp/process-changes changes)))
ptk/WatchEvent
(watch [_ state stream]
(let [changes (::batched-changes state)]
@ -1277,7 +1282,7 @@
(ptk/reify ::go-to
ptk/WatchEvent
(watch [_ state stream]
(let [file-id (get-in state [:workspace-local :file-id])
(let [file-id (get-in state [:workspace-page :file-id])
path-params {:file-id file-id}
query-params {:page-id page-id}]
(rx/of (rt/nav :workspace path-params query-params))))))

View file

@ -34,8 +34,8 @@
stoper (rx/filter uws/mouse-up? stream)
position @uws/mouse-position]
(rx/concat
(when (refs/alignment-activated? flags)
(rx/of (dw/initial-selection-align selected)))
;; (when (refs/alignment-activated? flags)
;; (rx/of (dw/initial-selection-align selected)))
(->> (uws/mouse-position-deltas position)
(rx/map #(dw/apply-temporal-displacement-in-bulk selected %))
(rx/take-until stoper))

View file

@ -59,8 +59,9 @@
(scroll/scroll-to-point dom mouse-point scroll-position))))
(mf/defc workspace-content
[{:keys [layout page file flags] :as params}]
[{:keys [page file flags] :as params}]
(let [canvas (mf/use-ref nil)
layout (mf/deref refs/workspace-layout)
left-sidebar? (not (empty? (keep layout [:layers :sitemap
:document-history])))
right-sidebar? (not (empty? (keep layout [:icons :drawtools
@ -68,6 +69,9 @@
classes (classnames
:no-tool-bar-right (not right-sidebar?)
:no-tool-bar-left (not left-sidebar?))]
[:*
(when (:colorpalette layout)
[:& colorpalette])
[:main.main-content
[:section.workspace-content
@ -90,7 +94,7 @@
(when left-sidebar?
[:& left-sidebar {:file file :page page :layout layout}])
(when right-sidebar?
[:& right-sidebar {:page page :layout layout}])]))
[:& right-sidebar {:page page :layout layout}])]]))
(mf/defc workspace
[{:keys [file-id page-id] :as props}]
@ -106,30 +110,18 @@
(st/emit! (dw/initialize-ws file-id))
#(st/emit! (dw/finalize-ws file-id)))})
;; (mf/use-effect
;; {:deps (mf/deps file-id page-id)
;; :fn #(st/emit! (dw/initialize-page page-id))})
(mf/use-effect
{:deps (mf/deps file-id page-id)
:fn (fn []
(let [sub (shortcuts/init)]
#(rx/cancel! sub)))})
(let [layout (mf/deref refs/workspace-layout)
flags (mf/deref refs/selected-flags)
file (mf/deref refs/workspace-file)
page (mf/deref refs/workspace-page)]
(let [file (mf/deref refs/workspace-file)
page (mf/deref refs/workspace-page)]
[:> rdnd/provider {:backend rdnd/html5}
[:& messages-widget]
[:& header {:page page :layout layout :flags flags}]
[:& header {:page page}]
(when (:colorpalette layout)
[:& colorpalette])
(when (and layout page)
[:& workspace-content {:layout layout
:flags flags
:file file
(when page
[:& workspace-content {:file file
:page page}])]))

View file

@ -62,13 +62,15 @@
;; --- Header Component
(mf/defc header
[{:keys [page layout flags] :as props}]
[{:keys [page] :as props}]
(let [toggle #(st/emit! (dw/toggle-flag %))
toggle-layout #(st/emit! (dw/toggle-layout-flag %))
on-undo #(st/emit! (udu/undo))
on-redo #(st/emit! (udu/redo))
on-image #(modal/show! import-image-modal {})
;;on-download #(udl/open! :download)
layout (mf/deref refs/workspace-layout)
flags (mf/deref refs/selected-flags)
file (mf/deref refs/workspace-file)
selected-drawtool (mf/deref refs/selected-drawing-tool)
select-drawtool #(st/emit! :interrupt