mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 11:06:12 +02:00
Add active theme toggling
This commit is contained in:
parent
f0e0e9334e
commit
9a745ea8bc
7 changed files with 46 additions and 5 deletions
|
@ -254,6 +254,11 @@
|
|||
[:type [:= :add-temporary-token-theme]]
|
||||
[:token-theme ::ctot/token-theme]]]
|
||||
|
||||
[:update-active-token-themes
|
||||
[:map {:title "UpdateActiveTokenThemes"}
|
||||
[:type [:= :update-active-token-themes]]
|
||||
[:theme-ids [:set ::sm/uuid]]]]
|
||||
|
||||
[:delete-temporary-token-theme
|
||||
[:map {:title "DeleteTemporaryTokenThemeChange"}
|
||||
[:type [:= :delete-temporary-token-theme]]
|
||||
|
@ -790,6 +795,10 @@
|
|||
[data {:keys [token-theme]}]
|
||||
(ctotl/add-temporary-token-theme data token-theme))
|
||||
|
||||
(defmethod process-change :update-active-token-themes
|
||||
[data {:keys [theme-ids]}]
|
||||
(ctotl/assoc-active-token-themes data theme-ids))
|
||||
|
||||
(defmethod process-change :delete-temporary-token-theme
|
||||
[data {:keys [id]}]
|
||||
(ctotl/delete-temporary-token-theme data id))
|
||||
|
|
|
@ -702,6 +702,13 @@
|
|||
(update :undo-changes conj {:type :delete-temporary-token-theme :id (:id token-theme)})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn update-active-token-themes
|
||||
[changes token-active-theme-ids prev-token-active-theme-ids]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :update-active-token-themes :theme-ids token-active-theme-ids})
|
||||
(update :undo-changes conj {:type :update-active-token-themes :theme-ids prev-token-active-theme-ids})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn add-token-theme
|
||||
[changes token-theme]
|
||||
(-> changes
|
||||
|
|
|
@ -65,8 +65,7 @@
|
|||
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]
|
||||
[:token-theme-temporary-id {:optional true}
|
||||
::sm/uuid]
|
||||
[:token-active-themes {:optional true
|
||||
:default #{}}
|
||||
[:token-active-themes {:optional true :default #{}}
|
||||
[:set ::sm/uuid]]
|
||||
[:token-themes {:optional true}
|
||||
[:vector ::sm/uuid]]
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
[token-set]
|
||||
(assoc token-set :modified-at (dt/now)))
|
||||
|
||||
(defn assoc-active-token-themes
|
||||
[file-data theme-ids]
|
||||
(assoc file-data :token-active-themes theme-ids))
|
||||
|
||||
(defn add-temporary-token-theme
|
||||
[file-data {:keys [id] :as token-theme}]
|
||||
(-> file-data
|
||||
|
|
|
@ -118,6 +118,16 @@
|
|||
theme))
|
||||
:else changes)))
|
||||
|
||||
(defn toggle-token-theme [token-theme-id]
|
||||
(ptk/reify ::toggle-token-theme
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [themes (wtts/get-active-theme-ids state)
|
||||
new-themes (wtts/toggle-active-theme-id token-theme-id state)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/update-active-token-themes new-themes themes))]
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(defn create-token-set [token-set]
|
||||
(let [new-token-set (merge
|
||||
{:id (uuid/next)
|
||||
|
|
|
@ -208,8 +208,9 @@
|
|||
[:button
|
||||
{:on-click (fn [e]
|
||||
(dom/prevent-default e)
|
||||
(dom/stop-propagation e))}
|
||||
(if (some-> active-theme-ids (get id)) "✅" "❎")]
|
||||
(dom/stop-propagation e)
|
||||
(st/emit! (wdt/toggle-token-theme id)))}
|
||||
(if (get active-theme-ids id) "✅" "❎")]
|
||||
[:button {:on-click (fn [e]
|
||||
(dom/prevent-default e)
|
||||
(dom/stop-propagation e)
|
||||
|
|
|
@ -18,11 +18,22 @@
|
|||
(group-by :group))))
|
||||
|
||||
(defn get-active-theme-ids [state]
|
||||
(get-in state [:workspace-data :token-active-themes]))
|
||||
(get-in state [:workspace-data :token-active-themes] #{}))
|
||||
|
||||
(defn get-temp-theme-id [state]
|
||||
(get-in state [:workspace-data :token-theme-temporary-id]))
|
||||
|
||||
(defn toggle-active-theme-id [theme-id state]
|
||||
(let [temp-theme-id (get-temp-theme-id state)
|
||||
themes (get-active-theme-ids state)
|
||||
theme-without-temp (disj themes temp-theme-id)
|
||||
new-themes (if (get theme-without-temp theme-id)
|
||||
(disj theme-without-temp theme-id)
|
||||
(conj theme-without-temp theme-id))]
|
||||
(if (empty? new-themes)
|
||||
#{temp-theme-id}
|
||||
new-themes)))
|
||||
|
||||
(defn update-theme-id
|
||||
[state]
|
||||
(let [active-themes (get-active-theme-ids state)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue