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

View file

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

View file

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

View file

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