1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-07 02:33:39 +02:00

Automatically hide notifications after a while

This commit is contained in:
Arne Schlüter 2018-06-11 19:53:06 +02:00
commit 82754fe39f
2 changed files with 22 additions and 10 deletions

View file

@ -200,19 +200,28 @@
;; user messages
(def notification-duration
{:info 2500
:error 10000})
(defn show-notification
"Displays an informative message to the user"
[db [_ level message]]
(let [id (.now js/performance)]
[fx [_ level message]]
(let [id (.now js/performance)
hide-later (fn [level]
[{:ms (get notification-duration level)
:dispatch [:notification/hide id]}])]
(if (nil? message)
(let [message level
level :info]
(assoc-in db [:notifications id] {:level level
:message message}))
(assoc-in db [:notifications id] {:level level
:message message}))))
(-> (assoc-in fx [:db :notifications id] {:level level
:message message})
(assoc :dispatch-later (hide-later level))))
(-> (assoc-in fx [:db :notifications id] {:level level
:message message})
(assoc :dispatch-later (hide-later level))))))
(re-frame/reg-event-db
(re-frame/reg-event-fx
:notification/show
show-notification)

View file

@ -51,8 +51,8 @@
(testing "remembering has no effect"
(is (nil? (events/try-remember-user {} [:_]))))))
(defn- first-notification [db]
(-> (:notifications db) vals first))
(defn- first-notification [fx]
(-> (get-in fx [:db :notifications]) vals first))
(deftest api-interaction
(testing "Should show an error notification when airsonic responds with an error"
@ -77,4 +77,7 @@
id (-> (:notifications state)
keys
first)]
(is (empty? (:notifications (events/hide-notification state [:_ id])))))))
(is (empty? (:notifications (events/hide-notification state [:_ id]))))))
(testing "Should automatically remove a message after a while"
(let [fx (events/show-notification {} [:_ :info "This is a notification"])]
(is (= :notification/hide (-> (:dispatch-later fx) first :dispatch first))))))