🐛 Prevent theme replacement on ranaming

This commit is contained in:
Andrey Antukh 2025-03-20 13:21:33 +01:00 committed by Andrés Moya
parent 9fb7456b38
commit 93bf198073
3 changed files with 22 additions and 19 deletions

View file

@ -91,16 +91,21 @@
(ptk/reify ::update-token-theme
ptk/WatchEvent
(watch [it state _]
(let [tokens-lib (get-tokens-lib state)
data (dsh/lookup-file-data state)
prev-token-theme (some-> tokens-lib (ctob/get-theme group name))
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/set-token-theme (:group prev-token-theme)
(:name prev-token-theme)
token-theme))]
(rx/of
(dch/commit-changes changes))))))
(let [data (dsh/lookup-file-data state)
tokens-lib (get data :tokens-lib)]
(if (and (or (not= group (:group token-theme))
(not= name (:name token-theme)))
(ctob/get-theme tokens-lib
(:group token-theme)
(:name token-theme)))
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
:type :toast
:level :error
:timeout 9000}))
(let [changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/set-token-theme group name token-theme))]
(rx/of (dch/commit-changes changes))))))))
(defn toggle-token-theme-active? [group name]
(ptk/reify ::toggle-token-theme-active?

View file

@ -253,7 +253,6 @@
(watch [_ state _]
(let [team-id (:current-team-id state)
file-id (:id file)]
(rx/of (dwn/initialize team-id file-id)
(dwsl/initialize-shape-layout)
(fetch-libraries file-id))))))

View file

@ -308,7 +308,6 @@
;; Form / Modal handlers
on-back #(set-state (constantly {:type :themes-overview}))
on-submit #(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] %))
disabled? (-> (:name theme-state)
(str/trim)
(str/empty?))
@ -320,16 +319,16 @@
on-save-form
(mf/use-fn
(mf/deps theme-state on-submit)
(mf/deps theme theme-state)
(fn [e]
(dom/prevent-default e)
(let [theme (-> theme-state
(update :name str/trim)
(update :group str/trim)
(update :description str/trim))]
(let [theme' (-> theme-state
(update :name str/trim)
(update :group str/trim)
(update :description str/trim))]
(when-not (str/empty? (:name theme))
(on-submit theme)))
(on-back)))
(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme')))
(on-back))))
close-modal
(mf/use-fn