mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 06:51:37 +02:00
Implement group theme switching
This commit is contained in:
parent
9a745ea8bc
commit
e8bbb75008
1 changed files with 43 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
||||||
(ns app.main.ui.workspace.tokens.token-set)
|
(ns app.main.ui.workspace.tokens.token-set
|
||||||
|
(:require
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
;; Themes ----------------------------------------------------------------------
|
;; Themes ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -23,17 +25,50 @@
|
||||||
(defn get-temp-theme-id [state]
|
(defn get-temp-theme-id [state]
|
||||||
(get-in state [:workspace-data :token-theme-temporary-id]))
|
(get-in state [:workspace-data :token-theme-temporary-id]))
|
||||||
|
|
||||||
|
(defn theme-ids-with-group [theme-id state]
|
||||||
|
(let [themes (get-workspace-themes-index state)
|
||||||
|
theme-group (get-in themes [theme-id :group])
|
||||||
|
same-group-theme-ids (->> themes
|
||||||
|
(eduction
|
||||||
|
(map val)
|
||||||
|
(filter #(= (:group %) theme-group))
|
||||||
|
(map :id))
|
||||||
|
(into #{}))]
|
||||||
|
same-group-theme-ids))
|
||||||
|
|
||||||
(defn toggle-active-theme-id [theme-id state]
|
(defn toggle-active-theme-id [theme-id state]
|
||||||
(let [temp-theme-id (get-temp-theme-id state)
|
(let [temp-theme-id-set (some->> (get-temp-theme-id state) (conj #{}))
|
||||||
themes (get-active-theme-ids state)
|
active-theme-ids (get-active-theme-ids state)
|
||||||
theme-without-temp (disj themes temp-theme-id)
|
add? (not (get active-theme-ids theme-id))
|
||||||
new-themes (if (get theme-without-temp theme-id)
|
;; Deactivate themes with the same group when activating a theme
|
||||||
(disj theme-without-temp theme-id)
|
same-group-ids (when add? (theme-ids-with-group theme-id state))
|
||||||
(conj theme-without-temp theme-id))]
|
theme-ids-without-same-group (set/difference active-theme-ids
|
||||||
|
same-group-ids
|
||||||
|
temp-theme-id-set)
|
||||||
|
new-themes (if add?
|
||||||
|
(conj theme-ids-without-same-group theme-id)
|
||||||
|
(disj theme-ids-without-same-group theme-id))]
|
||||||
(if (empty? new-themes)
|
(if (empty? new-themes)
|
||||||
#{temp-theme-id}
|
(or temp-theme-id-set #{})
|
||||||
new-themes)))
|
new-themes)))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(let [state {:workspace-data {:token-themes-index {1 {:id 1}}}}]
|
||||||
|
(toggle-active-theme-id 1 state))
|
||||||
|
|
||||||
|
(let [state {:workspace-data {:token-active-themes #{1}
|
||||||
|
:token-themes-index {1 {:id 1}}}}]
|
||||||
|
(toggle-active-theme-id 1 state))
|
||||||
|
|
||||||
|
(let [state {:workspace-data {:token-active-themes #{2 3 4}
|
||||||
|
:token-themes-index {1 {:id 1}
|
||||||
|
2 {:id 2}
|
||||||
|
3 {:id 3}
|
||||||
|
4 {:id 4 :group :different}}}}]
|
||||||
|
(toggle-active-theme-id 1 state))
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
(defn update-theme-id
|
(defn update-theme-id
|
||||||
[state]
|
[state]
|
||||||
(let [active-themes (get-active-theme-ids state)
|
(let [active-themes (get-active-theme-ids state)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue