From be24e1fb71512f35215d306b9419881588cee2ea Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Nov 2020 12:57:02 +0100 Subject: [PATCH] :sparkles: Improve specs usage on messages. --- frontend/src/app/main/data/messages.cljs | 38 ++++++++++++++++-------- frontend/src/app/main/ui/messages.cljs | 18 +++-------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/frontend/src/app/main/data/messages.cljs b/frontend/src/app/main/data/messages.cljs index c4837c0fb..a688c756b 100644 --- a/frontend/src/app/main/data/messages.cljs +++ b/frontend/src/app/main/data/messages.cljs @@ -9,32 +9,46 @@ (ns app.main.data.messages (:require - [beicon.core :as rx] - [cljs.spec.alpha :as s] - [potok.core :as ptk] [app.common.data :as d] [app.common.exceptions :as ex] [app.common.pages :as cp] [app.common.spec :as us] - [app.config :as cfg])) + [app.config :as cfg] + [beicon.core :as rx] + [cljs.spec.alpha :as s] + [potok.core :as ptk])) (declare hide) (declare show) (def +animation-timeout+ 600) -(s/def ::message-type #{:success :error :info :warning}) -(s/def ::message-position #{:fixed :floating :inline}) -(s/def ::message-status #{:visible :hide}) -(s/def ::message-controls #{:none :close :inline-actions :bottom-actions}) -(s/def ::message-tag string?) -(s/def ::label string?) +(s/def ::type #{:success :error :info :warning}) +(s/def ::position #{:fixed :floating :inline}) +(s/def ::status #{:visible :hide}) +(s/def ::controls #{:none :close :inline-actions :bottom-actions}) + +(s/def ::tag ::us/string) +(s/def ::label ::us/string) (s/def ::callback fn?) -(s/def ::message-action (s/keys :req-un [::label ::callback])) -(s/def ::message-actions (s/nilable (s/coll-of ::message-action :kind vector?))) +(s/def ::action (s/keys :req-un [::label ::callback])) +(s/def ::actions (s/every ::message-action :kind vector?)) +(s/def ::timeout ::us/integer) +(s/def ::content ::us/string) + +(s/def ::message + (s/keys :req-un [::type] + :opt-un [::status + ::position + ::controls + ::tag + ::timeout + ::actions + ::status])) (defn show [data] + (us/verify ::message data) (ptk/reify ::show ptk/UpdateEvent (update [_ state] diff --git a/frontend/src/app/main/ui/messages.cljs b/frontend/src/app/main/ui/messages.cljs index 0b41989bd..fc6f092bd 100644 --- a/frontend/src/app/main/ui/messages.cljs +++ b/frontend/src/app/main/ui/messages.cljs @@ -9,27 +9,17 @@ (ns app.main.ui.messages (:require - [rumext.alpha :as mf] - [clojure.spec.alpha :as s] - [app.common.uuid :as uuid] [app.common.spec :as us] - [app.main.ui.icons :as i] + [app.common.uuid :as uuid] [app.main.data.messages :as dm] [app.main.refs :as refs] [app.main.store :as st] - [app.util.data :refer [classnames]] + [app.main.ui.icons :as i] [app.util.dom :as dom] - [app.util.i18n :as i18n :refer [t]] - [app.util.timers :as ts])) + [rumext.alpha :as mf])) (mf/defc banner [{:keys [type position status controls content actions on-close] :as props}] - (us/assert ::dm/message-type type) - (us/assert ::dm/message-position position) - (us/assert ::dm/message-status status) - (us/assert ::dm/message-controls controls) - (us/assert ::dm/message-actions actions) - (us/assert (s/nilable ::us/fn) on-close) [:div.banner {:class (dom/classnames :warning (= type :warning) :error (= type :error) @@ -62,7 +52,7 @@ (mf/defc notifications [] (let [message (mf/deref refs/message) - on-close #(st/emit! dm/hide)] + on-close (st/emitf dm/hide)] (when message [:& banner (assoc message :position (or (:position message) :fixed)