Improve specs usage on messages.

This commit is contained in:
Andrey Antukh 2020-11-25 12:57:02 +01:00 committed by Hirunatan
parent 81e909b961
commit be24e1fb71
2 changed files with 30 additions and 26 deletions

View file

@ -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)