From: fr33domlover <fr33domlo...@rel4tion.org> Yesod supports multiple messages now, which makes this possible.
I left the AlertSpec test, just adapted it to the changes, but I must say it's somewhat useless now because Alerts is just a tiny tiny thin wrapper now. Also note the changes in the hamlet file, the design people should know what it looks like now. --- website/src/Alerts.hs | 20 +------------------- website/src/Foundation.hs | 4 +--- website/templates/default-layout.hamlet | 9 ++++----- website/test/AlertsSpec.hs | 11 +++++++---- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/website/src/Alerts.hs b/website/src/Alerts.hs index 1b81707..354c3ad 100644 --- a/website/src/Alerts.hs +++ b/website/src/Alerts.hs @@ -3,7 +3,6 @@ module Alerts , alertInfo , alertSuccess , alertWarning - , getAlert ) where import Prelude @@ -13,19 +12,8 @@ import Data.Text (Text) import Text.Blaze.Html.Renderer.Text (renderHtml) import qualified Data.Text.Lazy as TL -alertKey :: Text -alertKey = "_MSG_ALERT" - addAlert :: MonadHandler m => Text -> Html -> m () -addAlert level msg = do - render <- getUrlRenderParams - prev <- lookupSession alertKey - - setSession alertKey $ maybe id mappend prev $ TL.toStrict $ renderHtml $ - [hamlet| - <div .alert .alert-#{level}> - #{msg} - |] render +addAlert = addMessage alertDanger, alertInfo, alertSuccess, alertWarning :: MonadHandler m => Html -> m () @@ -33,9 +21,3 @@ alertDanger = addAlert "danger" alertInfo = addAlert "info" alertSuccess = addAlert "success" alertWarning = addAlert "warning" - -getAlert :: MonadHandler m => m (Maybe Html) -getAlert = do - mmsg <- fmap preEscapedToMarkup <$> lookupSession alertKey - deleteSession alertKey - return mmsg diff --git a/website/src/Foundation.hs b/website/src/Foundation.hs index 6948380..87b21b8 100644 --- a/website/src/Foundation.hs +++ b/website/src/Foundation.hs @@ -12,7 +12,6 @@ import qualified Data.List as List import qualified Data.Text as T import qualified Yesod.Core.Unsafe as Unsafe -import Alerts (getAlert) import AppDataTypes import Avatar import Email @@ -170,8 +169,7 @@ unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger navbarLayout :: Text -> Widget -> Handler Html navbarLayout pageName widget = do - mmsg <- getMessage - malert <- getAlert + msgs <- getMessages maybeUser <- maybeAuth avatar <- getUserAvatar (StaticR img_default_avatar_png) (fmap entityVal maybeUser) diff --git a/website/templates/default-layout.hamlet b/website/templates/default-layout.hamlet index b27e088..0759249 100644 --- a/website/templates/default-layout.hamlet +++ b/website/templates/default-layout.hamlet @@ -1,11 +1,10 @@ <div .grid> ^{navbar} <div .container> - $maybe msg <- mmsg - <div .alert .alert-info #message> - #{msg} - $maybe alert <- malert - #{alert} + <div #messages> + $forall (level, msg) <- msgs + <div .alert .alert-#{level}> + #{msg} <div *{pageClasses}> ^{widget} ^{footer} diff --git a/website/test/AlertsSpec.hs b/website/test/AlertsSpec.hs index 62235e8..39a3abc 100644 --- a/website/test/AlertsSpec.hs +++ b/website/test/AlertsSpec.hs @@ -11,10 +11,13 @@ alertSite = LiteApp go alertWarning "Hey bub" pure $ toTypedContent ("" :: Html) go _ ["get"] = Just $ do - malert <- getAlert - fmap toTypedContent $ defaultLayout $ case malert of - Just alert -> [whamlet|#{alert}|] - Nothing -> "" + msgs <- getMessages + fmap toTypedContent $ defaultLayout + [whamlet| + $forall (level, msg) <- msgs + <div .alert .alert-#{level}> + #{msg} + |] go _ _ = Nothing withAlertSite :: SpecWith (TestApp LiteApp) -> Spec -- 1.9.1 _______________________________________________ Dev mailing list Dev@lists.snowdrift.coop https://lists.snowdrift.coop/mailman/listinfo/dev