From 87c0c53df144fd26beafdfd204080a09dbfe483f Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 19 Mar 2021 15:23:12 +0100 Subject: [PATCH] mob#4 --- src/main/cljc/dda/k8s_mastodon_bot/core.cljc | 4 ++- .../cljs/dda/k8s_mastodon_bot/browser.cljs | 32 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) 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!)))))