0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 22:22:43 -05:00

Revert to use-var

This commit is contained in:
Florian Schroedl 2024-06-21 10:10:45 +02:00
parent e394216f00
commit f00ac72fbe

View file

@ -35,6 +35,9 @@
(me/humanize)) (me/humanize))
nil) nil)
(defn finalize-name [name]
(str/trim name))
(mf/defc form (mf/defc form
{::mf/wrap-props false} {::mf/wrap-props false}
[{:keys [token] :as _args}] [{:keys [token] :as _args}]
@ -52,22 +55,23 @@
:description ""} :description ""}
token)) token))
state @state* state @state*
_ (js/console.log "render")
;; Name ;; Name
finalize-name str/trim name (mf/use-var (or (:name token) ""))
name-errors (mf/use-state nil)
name-schema (mf/use-memo name-schema (mf/use-memo
(mf/deps existing-token-names) (mf/deps existing-token-names)
(fn [] #(token-name-schema existing-token-names))
(token-name-schema existing-token-names)))
on-update-name (fn [e] on-update-name (fn [e]
(let [value (dom/get-target-val e) (let [value (dom/get-target-val e)
errors (->> (finalize-name value) errors (->> (finalize-name value)
(m/explain name-schema))] (m/explain name-schema))]
(swap! state* merge {:name value (reset! name value)
:errors/name errors}))) (reset! name-errors errors)))
disabled? (or disabled? (or
(empty? (finalize-name (:name state))) @name-errors
(:errors/name state))] (empty? (finalize-name (:name state))))]
;; on-update-name (fn [e] ;; on-update-name (fn [e]
;; (let [{:keys [errors] :as state} (mf/deref state*) ;; (let [{:keys [errors] :as state} (mf/deref state*)
@ -101,12 +105,13 @@
[:div {:class (stl/css :token-rows)} [:div {:class (stl/css :token-rows)}
[:div [:div
[:& tokens.common/labeled-input {:label "Name" [:& tokens.common/labeled-input {:label "Name"
:error? (:errors/name state) :error? @name-errors
:input-props {:default-value (:name state) :input-props {:default-value (:name state)
:auto-focus true :auto-focus true
:on-change on-update-name}}] :on-change on-update-name}}]
(when-let [errors (:errors/name state)] (when @name-errors
[:p {:class (stl/css :error)} (me/humanize errors)])] [:p {:class (stl/css :error)}
(me/humanize @name-errors)])]
[:& tokens.common/labeled-input {:label "Value" [:& tokens.common/labeled-input {:label "Value"
:input-props {:default-value (:value state) :input-props {:default-value (:value state)
#_#_:on-change #(on-update-field idx %)}}] #_#_:on-change #(on-update-field idx %)}}]