mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 08:11:39 +02:00
Create temporary theme when creating set
This commit is contained in:
parent
9329513949
commit
879ef1123f
7 changed files with 85 additions and 12 deletions
|
@ -147,17 +147,31 @@
|
|||
selected-token-set-id (if create-set?
|
||||
(:id new-token-set)
|
||||
(:id token-set))
|
||||
changes (cond
|
||||
create-set? (-> token-changes
|
||||
(pcb/add-token-set new-token-set))
|
||||
:else (let [updated-token-set (if (contains? token-set (:id token))
|
||||
token-set
|
||||
(update token-set :tokens conj (:id token)))]
|
||||
(-> token-changes
|
||||
(pcb/update-token-set updated-token-set token-set))))]
|
||||
set-changes (cond
|
||||
create-set? (-> token-changes
|
||||
(pcb/add-token-set new-token-set))
|
||||
:else (let [updated-token-set (if (contains? token-set (:id token))
|
||||
token-set
|
||||
(update token-set :tokens conj (:id token)))]
|
||||
(-> token-changes
|
||||
(pcb/update-token-set updated-token-set token-set))))
|
||||
theme-id (wtts/update-theme-id state)
|
||||
theme (some-> theme-id (wtts/get-workspace-token-theme state))
|
||||
theme-changes (cond
|
||||
(not theme-id) (-> set-changes
|
||||
(pcb/add-temporary-token-theme
|
||||
|
||||
{:id (uuid/next)
|
||||
:name ""
|
||||
:sets #{selected-token-set-id}}))
|
||||
create-set? (-> set-changes
|
||||
(pcb/update-token-theme
|
||||
(wtts/add-token-set-to-token-theme selected-token-set-id theme)
|
||||
theme))
|
||||
:else set-changes)]
|
||||
(rx/of
|
||||
(set-selected-token-set-id selected-token-set-id)
|
||||
(dch/commit-changes changes)))))))
|
||||
(dch/commit-changes theme-changes)))))))
|
||||
|
||||
(defn delete-token
|
||||
[id]
|
||||
|
|
|
@ -17,8 +17,26 @@
|
|||
(->> (map #(get themes-index %) themes)
|
||||
(group-by :group))))
|
||||
|
||||
(defn theme-selected? [theme]
|
||||
(= :enabled (:selected theme)))
|
||||
(defn get-active-theme-ids [state]
|
||||
(:token-active-themes state))
|
||||
|
||||
(defn get-temp-theme-id [state]
|
||||
(:token-theme-temporary-id state))
|
||||
|
||||
(defn update-theme-id
|
||||
[state]
|
||||
(let [active-themes (get-active-theme-ids state)
|
||||
temporary-theme-id (get-temp-theme-id state)]
|
||||
(cond
|
||||
(empty? active-themes) temporary-theme-id
|
||||
(= 1 (count active-themes)) (first active-themes)
|
||||
:else temporary-theme-id)))
|
||||
|
||||
(defn get-workspace-token-theme [id state]
|
||||
(get-in state (get-in state [:workspace-data :token-sets-index id])))
|
||||
|
||||
(defn add-token-set-to-token-theme [token-set-id token-theme]
|
||||
(update token-theme :sets conj token-set-id))
|
||||
|
||||
;; Sets ------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue