diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 9d1e90a50e..24fd4d4d25 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -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}) diff --git a/common/src/app/common/types/tokens_theme_list.cljc b/common/src/app/common/types/tokens_theme_list.cljc index bcd15bf5a1..98c8e5d01f 100644 --- a/common/src/app/common/types/tokens_theme_list.cljc +++ b/common/src/app/common/types/tokens_theme_list.cljc @@ -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)))))) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index c96f673f30..7b055f73a6 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -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)))] diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 337781616c..976c7f7385 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -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