From 864338174a24fd53b3cfd4da5e25b5475eb92f67 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 25 Jul 2019 08:38:01 +0200 Subject: [PATCH] refactor(alert messages): custom icons without js --- frontend/src/utils/alerts/alert-icons.js | 20 -------------- frontend/src/utils/alerts/alerts.js | 9 ------- frontend/src/utils/alerts/alerts.scss | 33 ++++++++++++++++-------- src/Foundation.hs | 12 ++++++--- templates/widgets/alerts/alerts.hamlet | 16 ++++-------- 5 files changed, 35 insertions(+), 55 deletions(-) delete mode 100644 frontend/src/utils/alerts/alert-icons.js diff --git a/frontend/src/utils/alerts/alert-icons.js b/frontend/src/utils/alerts/alert-icons.js deleted file mode 100644 index 434d98568..000000000 --- a/frontend/src/utils/alerts/alert-icons.js +++ /dev/null @@ -1,20 +0,0 @@ -// -// Fontawesome icons to be used on alerts. -// -// If you want to add new icons stick to the format of the existing ones. -// They are necessary due to weird unicode conversions during transpilation. -// https://fontawesome.com/icons - -export const ALERT_ICONS = { - calendarcheck: '"\\f274"', - calendartimes: '"\\f273"', - checkmark: '"\\f058"', - cross: '"\\f00d"', - deregistered: '"\\f273"', - exclamation: '"\\f06a"', - info: '"\\f05a"', - registered: '"\\f274"', - userplus: '"\\f234"', - userslash: '"\\f506"', - warning: '"\\f071"', -}; diff --git a/frontend/src/utils/alerts/alerts.js b/frontend/src/utils/alerts/alerts.js index 4d1a1cf7a..e54f898fd 100644 --- a/frontend/src/utils/alerts/alerts.js +++ b/frontend/src/utils/alerts/alerts.js @@ -1,6 +1,5 @@ import { Utility } from '../../core/utility'; import './alerts.scss'; -import { ALERT_ICONS } from './alert-icons'; const ALERTS_INITIALIZED_CLASS = 'alerts--initialized'; const ALERTS_ELEVATED_CLASS = 'alerts--elevated'; @@ -20,7 +19,6 @@ const ALERT_AUTOCLOSING_MATCHER = '.alert-info, .alert-success'; /* * Dataset-Inputs: * - decay (data-decay): Custom time (in seconds) for this alert to stay visible - * - icon (data-icon): Custom icon (from the list in alert-icons.js) to show on the alert */ @Utility({ @@ -94,13 +92,6 @@ export class Alerts { this._toggleAlert(alertElement); }); - const customIcon = alertElement.dataset.icon; - if (customIcon && ALERT_ICONS[customIcon]) { - alertElement.style.setProperty('--alert-icon', ALERT_ICONS[customIcon]); - } else if (customIcon) { - throw new Error('Alert: Custom icon "' + customIcon + '" could not be found!'); - } - if (autoHideDelay > 0 && alertElement.matches(ALERT_AUTOCLOSING_MATCHER)) { window.setTimeout(() => this._toggleAlert(alertElement), autoHideDelay * 1000); } diff --git a/frontend/src/utils/alerts/alerts.scss b/frontend/src/utils/alerts/alerts.scss index 8beff3b70..aa2f6acdc 100644 --- a/frontend/src/utils/alerts/alerts.scss +++ b/frontend/src/utils/alerts/alerts.scss @@ -32,6 +32,10 @@ font-size: 30px; transform: translateX(-50%); } + + &:hover::before { + color: var(--color-grey-medium); + } } .alerts--elevated { @@ -68,6 +72,10 @@ .alert a { color: var(--color-lightwhite); + + &:hover { + color: var(--color-grey); + } } @keyframes slide-in-alert { @@ -124,9 +132,9 @@ z-index: 40; &::before { - content: var(--alert-icon, var(--alert-icon-default, '\f05a')); + /* content: var(--alert-icon, var(--alert-icon-default, '\f05a')); */ position: absolute; - font-family: 'Font Awesome 5 Free'; + /* font-family: 'Font Awesome 5 Free'; */ font-size: 24px; top: 50%; left: 50%; @@ -188,23 +196,26 @@ .alert-success { background-color: var(--color-success); - .alert__icon::before { - --alert-icon-default: '\f058'; - } + /* .alert__icon::before { + * --alert-icon-default: '\f058'; + * } + */ } .alert-warning { background-color: var(--color-warning); - .alert__icon::before { - --alert-icon-default: '\f06a'; - } + /* .alert__icon::before { + * --alert-icon-default: '\f06a'; + * } + */ } .alert-error { background-color: var(--color-error); - .alert__icon::before { - --alert-icon-default: '\f071'; - } + /* .alert__icon::before { + * --alert-icon-default: '\f071'; + * } + */ } diff --git a/src/Foundation.hs b/src/Foundation.hs index a2df4f68c..4f345261c 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1216,10 +1216,8 @@ instance Yesod UniWorX where , massInputShortcircuit ] - lift . bracketOnError getMessages (mapM_ addMessage') $ \msgs -> do - -- @gkleen: the following line is redundant, but what does this block do anyway? - -- Just msgs' <- return . forM msgs $ \(msgState, content) -> Message <$> fromPathPiece msgState <*> return content - addCustomHeader HeaderAlerts . decodeUtf8 . urlEncode True . toStrict $ JSON.encode msgs + lift . bracketOnError getMessages (mapM_ addMessage') $ + addCustomHeader HeaderAlerts . decodeUtf8 . urlEncode True . toStrict . JSON.encode -- Since we implement `errorHandler` ourselves we don't need `defaultMessageWidget` defaultMessageWidget _title _body = error "defaultMessageWidget: undefined" @@ -2839,6 +2837,12 @@ instance YesodAuth UniWorX where authHttpManager = Yesod.getHttpManager + onLogin = addMessageI Success Auth.NowLoggedIn + + onErrorHtml dest msg = do + addMessage Error $ toHtml msg + redirect dest + renderAuthMessage _ _ = Auth.germanMessage -- TODO instance YesodAuthPersist UniWorX diff --git a/templates/widgets/alerts/alerts.hamlet b/templates/widgets/alerts/alerts.hamlet index 0dd303f8a..dca147265 100644 --- a/templates/widgets/alerts/alerts.hamlet +++ b/templates/widgets/alerts/alerts.hamlet @@ -2,14 +2,8 @@ $newline never
$forall Message{..} <- mmsgs - $with icn <- maybeAttribute "data-icon" iconJS messageIcon -
-
-
-
- #{messageContent} - +
+
+
+
+ #{messageContent}