♻️ Refactor workspace state organization

Move many local to a specific global prop.
This commit is contained in:
Andrey Antukh 2022-02-24 23:42:45 +01:00 committed by Alonso Torres
parent 6e667e078c
commit f05518e357
14 changed files with 133 additions and 171 deletions

View file

@ -8,6 +8,7 @@
"A collection of derived refs."
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.path.commands :as upc]
@ -72,12 +73,12 @@
(def dashboard-selected-project
(l/derived (fn [state]
(get-in state [:dashboard-local :selected-project]))
(dm/get-in state [:dashboard-local :selected-project]))
st/state))
(def dashboard-selected-files
(l/derived (fn [state]
(let [get-file #(get-in state [:dashboard-files %])
(let [get-file #(dm/get-in state [:dashboard-files %])
sim-file #(select-keys % [:id :name :project-id :is-shared])
selected (get-in state [:dashboard-local :selected-files])
xform (comp (map get-file)
@ -91,6 +92,9 @@
(def workspace-local
(l/derived :workspace-local st/state))
(def workspace-global
(l/derived :workspace-global st/state))
(def workspace-drawing
(l/derived :workspace-drawing st/state))
@ -101,41 +105,6 @@
[id]
(l/derived #(contains? % id) selected-shapes))
(def viewport-data
(l/derived #(select-keys % [:options-mode
:zoom
:vport
:vbox
:edition
:edit-path
:tooltip
:panning
:zooming
:picking-color?
:transform
:hover
:modifiers
:selrect
:show-distances?])
workspace-local =))
(def interactions-data
(l/derived #(select-keys % [:editing-interaction-index
:draw-interaction-to
:draw-interaction-to-frame
:move-overlay-to
:move-overlay-index])
workspace-local =))
(def typography-data
(l/derived #(select-keys % [:rename-typography
:edit-typography])
workspace-local =))
(def local-displacement
(l/derived #(select-keys % [:modifiers :selected])
workspace-local =))
(def selected-zoom
(l/derived :zoom workspace-local))
@ -167,15 +136,13 @@
(l/derived :hover-ids context-menu))
(def selected-assets
(l/derived :selected-assets workspace-local))
(l/derived :selected-assets workspace-global))
(def workspace-layout
(l/derived :workspace-layout st/state))
(def current-file-id
(l/derived :current-file-id st/state))
(def workspace-file
"A ref to a striped vision of file (without data)."
(l/derived (fn [state]
(let [file (:workspace-file state)
data (:workspace-data state)]
@ -193,12 +160,12 @@
(def workspace-recent-colors
(l/derived (fn [state]
(get-in state [:workspace-data :recent-colors] []))
(dm/get-in state [:workspace-data :recent-colors] []))
st/state))
(def workspace-recent-fonts
(l/derived (fn [state]
(get-in state [:workspace-data :recent-fonts] []))
(dm/get-in state [:workspace-data :recent-fonts] []))
st/state))
(def workspace-file-typography
@ -215,7 +182,7 @@
(def workspace-local-library
(l/derived (fn [state]
(select-keys (get state :workspace-data)
(select-keys (:workspace-data state)
[:id
:colors
:media
@ -236,7 +203,7 @@
(l/derived (fn [state]
(let [page-id (:current-page-id state)
data (:workspace-data state)]
(get-in data [:pages-index page-id])))
(dm/get-in data [:pages-index page-id])))
st/state))
(def workspace-page-objects
@ -271,7 +238,7 @@
(defn- set-content-modifiers [state]
(fn [id shape]
(let [content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])]
(let [content-modifiers (dm/get-in state [:workspace-local :edit-path id :content-modifiers])]
(if (some? content-modifiers)
(update shape :content upc/apply-content-modifiers content-modifiers)
shape))))
@ -343,7 +310,7 @@
(def users
(l/derived :users st/state))
(def fullscreen?
(l/derived (fn [state]
(get-in state [:viewer-local :fullscreen?] []))
st/state))
(def viewer-fullscreen?
(l/derived (fn [state]
(dm/get-in state [:viewer-local :fullscreen?]))
st/state))