From 57c60716f0e555a72d458d13f12ca2a630033313 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:12:36 +0200 Subject: [PATCH] :sparkles: Add minor improvements to notifications-hub component --- frontend/src/app/main/ui/messages.cljs | 57 ++++++++++--------- .../ui/notifications/toast_notification.cljs | 10 ++-- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/frontend/src/app/main/ui/messages.cljs b/frontend/src/app/main/ui/messages.cljs index 00df9c3f3..ba40ad1cf 100644 --- a/frontend/src/app/main/ui/messages.cljs +++ b/frontend/src/app/main/ui/messages.cljs @@ -17,33 +17,38 @@ (mf/defc notifications-hub [] (let [message (mf/deref refs/message) - - on-close #(st/emit! dmsg/hide) - - toast-message {:type (or (:type message) :info) - :links (:links message) - :on-close on-close - :content (:content message)} - - inline-message {:actions (:actions message) - :links (:links message) - :content (:content message)} - - context-message {:type (or (:type message) :info) - :links (:links message) - :content (:content message)} - - is-context-msg (and (nil? (:timeout message)) (nil? (:actions message))) - is-toast-msg (or (= :toast (:notification-type message)) (some? (:timeout message))) - is-inline-msg (or (= :inline (:notification-type message)) (and (some? (:position message)) (= :floating (:position message))))] + on-close (mf/use-fn #(st/emit! dmsg/hide)) + context? (and (nil? (:timeout message)) + (nil? (:actions message))) + inline? (or (= :inline (:notification-type message)) + (= :floating (:position message))) + toast? (or (= :toast (:notification-type message)) + (some? (:timeout message)))] (when message (cond - is-toast-msg - [:& toast-notification toast-message] - is-inline-msg - [:& inline-notification inline-message] - is-context-msg - [:& context-notification context-message] + toast? + [:& toast-notification + {:type (or (:type message) :info) + :links (:links message) + :on-close on-close + :content (:content message)}] + + inline? + [:& inline-notification + {:actions (:actions message) + :links (:links message) + :content (:content message)}] + + context? + [:& context-notification + {:type (or (:type message) :info) + :links (:links message) + :content (:content message)}] + :else - [:& toast-notification toast-message])))) + [:& toast-notification + {:type (or (:type message) :info) + :links (:links message) + :on-close on-close + :content (:content message)}])))) diff --git a/frontend/src/app/main/ui/notifications/toast_notification.cljs b/frontend/src/app/main/ui/notifications/toast_notification.cljs index c4583c901..639e605c0 100644 --- a/frontend/src/app/main/ui/notifications/toast_notification.cljs +++ b/frontend/src/app/main/ui/notifications/toast_notification.cljs @@ -38,12 +38,10 @@ neutral-icon)) (mf/defc toast-notification - "These are ephemeral elements that disappear when - the close button is pressed, - the page is refreshed, - the page is navigated to another page or - after 7 seconds, which is enough time to be read, - except for error messages that require user interaction." + "These are ephemeral elements that disappear when the close button + is pressed, the page is refreshed, the page is navigated to another + page or after 7 seconds, which is enough time to be read, except for + error messages that require user interaction." {::mf/props :obj} [{:keys [type content on-close links] :as props}]