diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 415c06bbb3..7c234838f3 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -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? diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 1f353c4ac7..2c1a00620d 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -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)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index cdeec2753e..d07a992815 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -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