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:
parent
aa04e68545
commit
82754fe39f
2 changed files with 22 additions and 10 deletions
|
|
@ -200,19 +200,28 @@
|
||||||
|
|
||||||
;; user messages
|
;; user messages
|
||||||
|
|
||||||
|
(def notification-duration
|
||||||
|
{:info 2500
|
||||||
|
:error 10000})
|
||||||
|
|
||||||
(defn show-notification
|
(defn show-notification
|
||||||
"Displays an informative message to the user"
|
"Displays an informative message to the user"
|
||||||
[db [_ level message]]
|
[fx [_ level message]]
|
||||||
(let [id (.now js/performance)]
|
(let [id (.now js/performance)
|
||||||
|
hide-later (fn [level]
|
||||||
|
[{:ms (get notification-duration level)
|
||||||
|
:dispatch [:notification/hide id]}])]
|
||||||
(if (nil? message)
|
(if (nil? message)
|
||||||
(let [message level
|
(let [message level
|
||||||
level :info]
|
level :info]
|
||||||
(assoc-in db [:notifications id] {:level level
|
(-> (assoc-in fx [:db :notifications id] {:level level
|
||||||
:message message}))
|
:message message})
|
||||||
(assoc-in db [:notifications id] {:level level
|
(assoc :dispatch-later (hide-later level))))
|
||||||
:message message}))))
|
(-> (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
|
:notification/show
|
||||||
show-notification)
|
show-notification)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@
|
||||||
(testing "remembering has no effect"
|
(testing "remembering has no effect"
|
||||||
(is (nil? (events/try-remember-user {} [:_]))))))
|
(is (nil? (events/try-remember-user {} [:_]))))))
|
||||||
|
|
||||||
(defn- first-notification [db]
|
(defn- first-notification [fx]
|
||||||
(-> (:notifications db) vals first))
|
(-> (get-in fx [:db :notifications]) vals first))
|
||||||
|
|
||||||
(deftest api-interaction
|
(deftest api-interaction
|
||||||
(testing "Should show an error notification when airsonic responds with an error"
|
(testing "Should show an error notification when airsonic responds with an error"
|
||||||
|
|
@ -77,4 +77,7 @@
|
||||||
id (-> (:notifications state)
|
id (-> (:notifications state)
|
||||||
keys
|
keys
|
||||||
first)]
|
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))))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue