From 8dc3165e54c45abe9e6de044c5af980052f4e2f4 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 14 Sep 2020 15:47:49 +0200 Subject: [PATCH] :bug: Fixes problems with saved grids --- common/app/common/pages.cljc | 30 ++++++++++++++++++- .../src/app/main/data/workspace/grid.cljs | 4 ++- frontend/src/app/main/refs.cljs | 4 --- .../workspace/sidebar/options/frame_grid.cljs | 6 +++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/common/app/common/pages.cljc b/common/app/common/pages.cljc index 8e625f5f2..9ba815a54 100644 --- a/common/app/common/pages.cljc +++ b/common/app/common/pages.cljc @@ -46,10 +46,38 @@ (<= % max-safe-int))) ;; Page Options +(s/def :internal.page.grid.color/value string?) +(s/def :internal.page.grid.color/opacity number?) -;; TODO: missing specs for :saved-grids +(s/def :internal.page.grid/size ::safe-integer) +(s/def :internal.page.grid/color + (s/keys :req-un [:internal.page.grid.color/value + :internal.page.grid.color/opacity])) + +(s/def :internal.page.grid/type #{:stretch :left :center :right}) +(s/def :internal.page.grid/item-length (s/nilable ::safe-integer)) +(s/def :internal.page.grid/gutter (s/nilable ::safe-integer)) +(s/def :internal.page.grid/margin (s/nilable ::safe-integer)) + +(s/def :internal.page.grid/square + (s/keys :req-un [:internal.page.grid/size + :internal.page.grid/color])) + +(s/def :internal.page.grid/column + (s/keys :req-un [:internal.page.grid/size + :internal.page.grid/color + :internal.page.grid/type + :internal.page.grid/item-length + :internal.page.grid/gutter + :internal.page.grid/margin])) + +(s/def :internal.page.grid/row :internal.page.grid/column) (s/def :internal.page.options/background string?) +(s/def :internal.page.options/saved-grids + (s/keys :req-un [:internal.page.grid/square + :internal.page.grid/row + :internal.page.grid/column])) (s/def :internal.page/options (s/keys :opt-un [:internal.page.options/background])) diff --git a/frontend/src/app/main/data/workspace/grid.cljs b/frontend/src/app/main/data/workspace/grid.cljs index 11f2f10db..9d7019087 100644 --- a/frontend/src/app/main/data/workspace/grid.cljs +++ b/frontend/src/app/main/data/workspace/grid.cljs @@ -75,11 +75,13 @@ ptk/WatchEvent (watch [_ state stream] (let [pid (:current-page-id state) - prev-value (get-in state [:workspace-data pid :options :saved-grids type])] + prev-value (get-in state [:workspace-data :pages-index pid :options :saved-grids type])] (rx/of (dwc/commit-changes [{:type :set-option + :page-id pid :option [:saved-grids type] :value params}] [{:type :set-option + :page-id pid :option [:saved-grids type] :value prev-value}] {:commit-local? true})))))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index c8d169ccb..361d9a580 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -140,10 +140,6 @@ (def workspace-page-options (l/derived :options workspace-page)) -;; TODO: revisit -(def workspace-saved-grids - (l/derived :saved-grids workspace-page-options)) - (def workspace-frames (l/derived cph/select-frames workspace-page-objects)) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/frame_grid.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/frame_grid.cljs index 198957675..3848e7ea5 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/frame_grid.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/frame_grid.cljs @@ -10,6 +10,7 @@ (ns app.main.ui.workspace.sidebar.options.frame-grid (:require [rumext.alpha :as mf] + [okulary.core :as l] [app.util.dom :as dom] [app.util.data :as d] [app.common.math :as mth] @@ -26,6 +27,9 @@ [app.main.ui.components.dropdown :refer [dropdown]] [app.util.i18n :as i18n :refer [tr t]])) +(def workspace-saved-grids + (l/derived :saved-grids refs/workspace-page-options)) + (mf/defc advanced-options [{:keys [visible? on-close children]}] (when visible? [:* @@ -229,7 +233,7 @@ (mf/defc frame-grid [{:keys [shape]}] (let [locale (i18n/use-locale) id (:id shape) - default-grid-params (merge dw/default-grid-params (mf/deref refs/workspace-saved-grids)) + default-grid-params (merge dw/default-grid-params (mf/deref workspace-saved-grids)) handle-create-grid #(st/emit! (dw/add-frame-grid id)) handle-remove-grid (fn [index] #(st/emit! (dw/remove-frame-grid id index))) handle-edit-grid (fn [index] #(st/emit! (dw/set-frame-grid id index %)))