diff options
| author | ckonstanski <carlos.konstanski@olo.com> | 2021-05-30 21:32:50 -0600 |
|---|---|---|
| committer | ckonstanski <carlos.konstanski@olo.com> | 2021-05-30 21:32:50 -0600 |
| commit | c3e83392a78690127f0840683d685a940ddbc2e6 (patch) | |
| tree | f73ae87da1eb2320b712202b459724d259e88636 /src | |
| parent | 66df485d7a24aa0bb3675cfb05821c86af491679 (diff) | |
Improved notification logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/org_ckons_cljs/notifications/core.cljs | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/src/org_ckons_cljs/notifications/core.cljs b/src/org_ckons_cljs/notifications/core.cljs index 3816fb3..fb60e98 100644 --- a/src/org_ckons_cljs/notifications/core.cljs +++ b/src/org_ckons_cljs/notifications/core.cljs @@ -4,9 +4,11 @@ [dommy.core :as dommy])) (declare template-message) -(declare template-error) -(declare maybe-error) +(declare template-errormsg) +(declare message-div-or-nil) +(declare errormsg-div-or-nil) (declare maybe-message) +(declare maybe-error) (hiccups/defhtml template-message [message] [:div {:class "alert alert-success"} message]) @@ -14,22 +16,70 @@ (hiccups/defhtml template-error [errormsg] [:div {:class "alert alert-danger"} errormsg]) +(defn message-div-or-nil [] + (when (not (empty? (dommy/html (dommy/sel1 :#message)))) + (dommy/html (dommy/sel1 :#message)))) + +(defn errormsg-div-or-nil [] + (when (not (empty? (dommy/html (dommy/sel1 :#errormsg)))) + (dommy/html (dommy/sel1 :#errormsg)))) + +;; loc-p | msg | msg-div || output +;; ------------------------------------- +;; f | f | f || nil +;; f | f | t || msg-div +;; f | t | - || msg +;; t | f | - || nil +;; t | t | - || msg +;; (defn maybe-message [jsonobj] - (when (get jsonobj "locationP") - (let [message (get jsonobj "message")] - (cond (empty? message) - (dommy/set-style! (dommy/sel1 :#message) :display "none") - :else - (do - (dommy/set-style! (dommy/sel1 :#message) :display "block") - (dommy/set-html! (dommy/sel1 :#message) (template-message message))))))) + (let [location-p (get jsonobj "locationP") + message (get jsonobj "message") + message-div (dommy/html (dommy/sel1 :#message))] + (dommy/set-html! (dommy/sel1 :#message) + (cond (or (and location-p + message) + (and (not location-p) + message)) + (template-message message) + (and (not location-p) + (not message) + (message-div-or-nil)) + (message-div-or-nil) + :else + "")) + (dommy/set-style! (dommy/sel1 :#message) + :display (cond (empty? (dommy/html (dommy/sel1 :#message))) + "none" + :else + "block")))) +;; loc-p | err | err-div || output +;; ------------------------------------- +;; f | f | f || nil +;; f | f | t || err-div +;; f | t | - || err +;; t | f | - || nil +;; t | t | - || err +;; (defn maybe-error [jsonobj] - (when (get jsonobj "locationP") - (let [errormsg (get jsonobj "errormsg")] - (cond (empty? errormsg) - (dommy/set-style! (dommy/sel1 :#errormsg) :display "none") - :else - (do - (dommy/set-style! (dommy/sel1 :#errormsg) :display "block") - (dommy/set-html! (dommy/sel1 :#errormsg) (template-error errormsg))))))) + (let [location-p (get jsonobj "locationP") + errormsg (get jsonobj "errormsg") + errormsg-div (dommy/html (dommy/sel1 :#errormsg))] + (dommy/set-html! (dommy/sel1 :#errormsg) + (cond (or (and location-p + errormsg) + (and (not location-p) + errormsg)) + (template-error errormsg) + (and (not location-p) + (not errormsg) + (errormsg-div-or-nil)) + (errormsg-div-or-nil) + :else + "")) + (dommy/set-style! (dommy/sel1 :#errormsg) + :display (cond (empty? (dommy/html (dommy/sel1 :#errormsg))) + "none" + :else + "block")))) |
