diff --git a/src/main/cljc/dda/k8s_mastodon_bot/core.cljc b/src/main/cljc/dda/k8s_mastodon_bot/core.cljc index df9737b..1dfe9d0 100644 --- a/src/main/cljc/dda/k8s_mastodon_bot/core.cljc +++ b/src/main/cljc/dda/k8s_mastodon_bot/core.cljc @@ -12,7 +12,9 @@ #?(:clj (alter-var-root #'s/*explain-out* (constantly expound/printer)) :cljs (set! s/*explain-out* expound/printer)) -(s/def ::config cd/config?) +(def config? cd/config?) + +(def auth? (s/keys :req-un [::cd/auth])) (defn generate-config [my-config my-auth] (-> diff --git a/src/main/cljs/dda/k8s_mastodon_bot/browser.cljs b/src/main/cljs/dda/k8s_mastodon_bot/browser.cljs index 1b328bd..312b188 100644 --- a/src/main/cljs/dda/k8s_mastodon_bot/browser.cljs +++ b/src/main/cljs/dda/k8s_mastodon_bot/browser.cljs @@ -17,13 +17,6 @@ (-> js/document (.getElementById "auth"))) -(defn set-config-validation! [input] - (print-debug input) - (-> js/document - (.getElementById "config-validation") - (.-innerHTML) - (set! input))) - (defn form [] (-> js/document (.getElementById "form"))) @@ -45,22 +38,21 @@ (defn set-config-validation-result! [validation-result] - (print-debug validation-result) - (set-config-validation! validation-result) + (-> js/document + (.getElementById "config-validation") + (.-innerHTML) + (set! validation-result)) (-> (config) (.setCustomValidity validation-result)) - (-> (form) - (.-classList) - (.add "was-validated")) validation-result) (defn validate-config! [] (let [config-str (config-from-document) config-map (edn/read-string config-str)] - (if (s/valid? ::core/config config-map) + (if (s/valid? core/config? config-map) (set-config-validation-result! "") (set-config-validation-result! - (expound/expound-str ::core/config config-map {:print-specs? false}))))) + (expound/expound-str core/config? config-map {:print-specs? false}))))) (defn set-validated! [] (-> (form) @@ -80,9 +72,11 @@ (defn validate-auth! [] (let [auth-str (auth-from-document) auth-map (edn/read-string auth-str)] - (when-not (s/valid? ::core/auth auth-map) + (print-debug (s/valid? core/auth? auth-map)) + (if (s/valid? core/auth? auth-map) + (set-auth-validation-result! "") (set-auth-validation-result! - (expound/expound-str ::core/auth auth-map {:print-specs? false}))))) + (expound/expound-str core/auth? auth-map {:print-specs? false}))))) (defn init [] (-> js/document @@ -93,4 +87,10 @@ (-> (config) (.addEventListener "blur" #(do (validate-config!) + (validate-auth!) + (set-validated!)))) + (-> (auth) + (.addEventListener "blur" + #(do (validate-config!) + (validate-auth!) (set-validated!)))))