mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
Wire up theme updating
This commit is contained in:
parent
70b570f112
commit
7aff690e7b
2 changed files with 62 additions and 35 deletions
|
@ -102,6 +102,17 @@
|
||||||
(rx/of
|
(rx/of
|
||||||
(dch/commit-changes changes)))))))
|
(dch/commit-changes changes)))))))
|
||||||
|
|
||||||
|
(defn update-token-theme [token-theme]
|
||||||
|
(ptk/reify ::update-token-theme
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [it state _]
|
||||||
|
(let [prev-token-theme (wtts/get-workspace-token-theme state (:id token-theme))
|
||||||
|
changes (-> (pcb/empty-changes it)
|
||||||
|
(pcb/update-token-theme token-theme prev-token-theme))]
|
||||||
|
(js/console.log "changes" changes)
|
||||||
|
(rx/of
|
||||||
|
(dch/commit-changes changes))))))
|
||||||
|
|
||||||
(defn ensure-token-theme-changes [changes state {:keys [id new-set?]}]
|
(defn ensure-token-theme-changes [changes state {:keys [id new-set?]}]
|
||||||
(let [theme-id (wtts/update-theme-id state)
|
(let [theme-id (wtts/update-theme-id state)
|
||||||
theme (some-> theme-id (wtts/get-workspace-token-theme state))]
|
theme (some-> theme-id (wtts/get-workspace-token-theme state))]
|
||||||
|
|
|
@ -8,15 +8,14 @@
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
[app.main.ui.components.radio-buttons :refer [radio-button radio-buttons]]
|
|
||||||
[app.main.ui.workspace.tokens.token-set :as wtts]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.main.ui.workspace.tokens.common :refer [labeled-input]]
|
|
||||||
[app.main.ui.workspace.tokens.sets :as wts]
|
|
||||||
[app.main.data.tokens :as wdt]
|
[app.main.data.tokens :as wdt]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.main.ui.components.radio-buttons :refer [radio-button radio-buttons]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
|
[app.main.ui.workspace.tokens.common :refer [labeled-input]]
|
||||||
|
[app.main.ui.workspace.tokens.sets :as wts]
|
||||||
|
[app.main.ui.workspace.tokens.token-set :as wtts]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
|
@ -97,7 +96,7 @@
|
||||||
"Create theme"]]]))
|
"Create theme"]]]))
|
||||||
|
|
||||||
(mf/defc edit-theme
|
(mf/defc edit-theme
|
||||||
[{:keys [token-sets theme on-back] :as props}]
|
[{:keys [token-sets theme on-back on-submit] :as props}]
|
||||||
(let [edit? (some? (:id theme))
|
(let [edit? (some? (:id theme))
|
||||||
theme-state (mf/use-state {:token-sets token-sets
|
theme-state (mf/use-state {:token-sets token-sets
|
||||||
:theme theme})
|
:theme theme})
|
||||||
|
@ -110,14 +109,22 @@
|
||||||
(fn [token-set-id]
|
(fn [token-set-id]
|
||||||
(swap! theme-state (fn [st]
|
(swap! theme-state (fn [st]
|
||||||
(update st :theme #(wtts/toggle-token-set-to-token-theme token-set-id %))))))
|
(update st :theme #(wtts/toggle-token-set-to-token-theme token-set-id %))))))
|
||||||
on-update-field (fn [field]
|
on-change-field (fn [field]
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(swap! theme-state (fn [st] (assoc-in st field (dom/get-target-val e))))))
|
(swap! theme-state (fn [st] (assoc-in st field (dom/get-target-val e))))))
|
||||||
on-update-group (on-update-field [:theme :group])
|
on-update-group (on-change-field [:theme :group])
|
||||||
on-update-name (on-update-field [:theme :name])]
|
on-update-name (on-change-field [:theme :name])
|
||||||
|
on-save-form (mf/use-callback
|
||||||
|
(mf/deps theme-state on-submit)
|
||||||
|
(fn [e]
|
||||||
|
(dom/prevent-default e)
|
||||||
|
(on-submit (:theme @theme-state))
|
||||||
|
(on-back)))]
|
||||||
|
[:form {:on-submit on-save-form}
|
||||||
[:div {:class (stl/css :edit-theme-wrapper)}
|
[:div {:class (stl/css :edit-theme-wrapper)}
|
||||||
[:div
|
[:div
|
||||||
[:button {:class (stl/css :back-button)
|
[:button {:class (stl/css :back-button)
|
||||||
|
:type "button"
|
||||||
:on-click on-back}
|
:on-click on-back}
|
||||||
chevron-icon "Back"]]
|
chevron-icon "Back"]]
|
||||||
[:div {:class (stl/css :edit-theme-inputs-wrapper)}
|
[:div {:class (stl/css :edit-theme-inputs-wrapper)}
|
||||||
|
@ -136,10 +143,18 @@
|
||||||
:on-toggle on-toggle-token-set}]]
|
:on-toggle on-toggle-token-set}]]
|
||||||
[:div {:class (stl/css :edit-theme-footer)}
|
[:div {:class (stl/css :edit-theme-footer)}
|
||||||
(when edit?
|
(when edit?
|
||||||
[:button {:class (stl/css :button-secondary)} "Delete"])
|
[:button {:class (stl/css :button-secondary)
|
||||||
|
:type "button"}
|
||||||
|
"Delete"])
|
||||||
[:div {:class (stl/css :button-footer)}
|
[:div {:class (stl/css :button-footer)}
|
||||||
[:button {:class (stl/css :button-secondary)} "Cancel"]
|
[:button {:class (stl/css :button-secondary)
|
||||||
[:button {:class (stl/css :button-primary)} "Save theme"]]]]))
|
:type "button"
|
||||||
|
:on-click #(st/emit! (modal/hide))}
|
||||||
|
"Cancel"]
|
||||||
|
[:button {:class (stl/css :button-primary)
|
||||||
|
:type "submit"
|
||||||
|
:on-click on-save-form}
|
||||||
|
"Save theme"]]]]]))
|
||||||
|
|
||||||
(mf/defc controlled-edit-theme
|
(mf/defc controlled-edit-theme
|
||||||
[{:keys [state set-state]}]
|
[{:keys [state set-state]}]
|
||||||
|
@ -149,7 +164,8 @@
|
||||||
[:& edit-theme
|
[:& edit-theme
|
||||||
{:token-sets token-sets
|
{:token-sets token-sets
|
||||||
:theme theme
|
:theme theme
|
||||||
:on-back #(set-state (constantly {:type :themes-overview}))}]))
|
:on-back #(set-state (constantly {:type :themes-overview}))
|
||||||
|
:on-submit #(st/emit! (wdt/update-token-theme %))}]))
|
||||||
|
|
||||||
(mf/defc themes
|
(mf/defc themes
|
||||||
[{:keys [] :as _args}]
|
[{:keys [] :as _args}]
|
||||||
|
|
Loading…
Reference in a new issue