0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Add token set deletion

This commit is contained in:
Florian Schroedl 2024-08-16 08:04:41 +02:00
parent ae39586d8c
commit 9329513949
4 changed files with 28 additions and 5 deletions

View file

@ -737,7 +737,7 @@
[changes token-set-id]
(assert-library! changes)
(let [library-data (::library-data (meta changes))
prev-token-set (get-in library-data [:token-set token-set-id])]
prev-token-set (get-in library-data [:token-sets-index token-set-id])]
(-> changes
(update :redo-changes conj {:type :del-token-set :id token-set-id})
(update :undo-changes conj {:type :add-token-set :token-set prev-token-set})

View file

@ -51,5 +51,8 @@
(d/update-in-when file-data [:token-sets-index token-set-id] #(-> (apply f % args) (touch))))
(defn delete-token-set
[file-data token-id]
file-data)
[file-data token-set-id]
(-> file-data
(update :token-set-groups (fn [xs] (into [] (remove #(= (:id %) token-set-id) xs))))
(update :token-sets-index dissoc token-set-id)
(update :token-themes-index (fn [xs] (update-vals xs #(update % :sets disj token-set-id))))))

View file

@ -116,6 +116,16 @@
(rx/of
(dch/commit-changes changes)))))))
(defn delete-token-set [token-set-id]
(ptk/reify ::delete-token-set
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/delete-token-set token-set-id))]
(rx/of (dch/commit-changes changes))))))
(defn update-create-token
[token]
(let [token (update token :id #(or % (uuid/next)))]

View file

@ -197,14 +197,24 @@
#_[:button "Delete"]]
[:ul
{:style {:list-style "disk"
:margin-left "20px"}}
:margin-left "20px"
:display "flex"
:flex-direction "column"
:gap "10px"}}
(for [[_ {:keys [id name]}] token-sets]
[:li {:style {:font-weight (when (= selected-token-set-id id) "bold")}
:on-click (fn []
(st/emit!
(wdt/set-selected-token-set-id id)
(wtu/update-workspace-tokens)))}
name])]
[:div {:style {:display "flex"
:justify-content "space-between"}}
name
[:button {:on-click (fn [e]
(dom/prevent-default e)
(dom/stop-propagation e)
(st/emit! (wdt/delete-token-set id)))}
"Delete"]]])]
[:hr]]))
(mf/defc tokens-explorer