Close success flash messages via delayed dispatch

This commit is contained in:
Teemu Patja 2017-02-21 23:00:53 +02:00
parent 4e627be1e0
commit 89475a9365
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C

View File

@ -13,6 +13,12 @@
:error-handler on-error :error-handler on-error
:finally finally :finally finally
:params params}))) :params params})))
(reg-fx
:delayed-dispatch
(fn [{:keys [args timeout]}]
(js/setTimeout #(dispatch args)
timeout)))
(reg-event-db (reg-event-db
:initialize-db :initialize-db
@ -24,10 +30,13 @@
(fn [db [_ path value]] (fn [db [_ path value]]
(assoc-in db path value))) (assoc-in db path value)))
(reg-event-db (reg-event-fx
:set-flash-message :set-flash-message
(fn [db [_ type text]] (fn [{:keys [db]} [_ type text]]
(assoc db :flash-message [type text]))) (merge {:db (assoc db :flash-message [type text])}
(when (= type :success)
{:delayed-dispatch {:args [:clear-flash-message]
:timeout 2000}}))))
(reg-event-db (reg-event-db
:clear-flash-message :clear-flash-message