Created
August 31, 2017 04:46
-
-
Save tippenein/3c6ab4fa34f3195ef0f7b3aa1b59d074 to your computer and use it in GitHub Desktop.
a simple flashMessage function for web app notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Eff.JQuery as Q | |
import Prelude hiding (div) | |
import Control.Monad.Eff | |
import Control.Monad.Eff.Timer (TIMER) | |
data Message | |
= Success | |
| Failure | |
| Info | |
| Warning | |
flashMessage :: forall eff. Message -> String -> Eff (timer :: TIMER | eff) Unit | |
flashMessage s msg = do | |
let klass = "alert-" <> msgToString s | |
alert <- Q.select ".alert" | |
Q.addClass klass alert | |
Q.display alert | |
Q.appendText msg =<< (Q.select "#app-message") | |
t <- timeout 5000 $ do | |
Q.removeClass klass alert | |
Q.hide alert | |
pure unit | |
pure unit | |
-- assumes bootstrap | |
msgToString :: Message -> String | |
msgToString Success = "success" | |
msgToString Info = "info" | |
msgToString Warning = "warning" | |
msgToString Failure = "danger" | |
type Milliseconds = Int | |
foreign import timeout :: forall a eff. | |
Milliseconds -> | |
Eff (timer :: TIMER | eff) a -> | |
Eff (timer :: TIMER | eff) Timeout | |
-- exports.timeout = function(time){ | |
-- return function(fn){ | |
-- return function(){ | |
-- return setTimeout(fn, time); | |
-- }; | |
-- }; | |
-- }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment