Skip to content

Instantly share code, notes, and snippets.

@tippenein
Created August 31, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tippenein/3c6ab4fa34f3195ef0f7b3aa1b59d074 to your computer and use it in GitHub Desktop.
Save tippenein/3c6ab4fa34f3195ef0f7b3aa1b59d074 to your computer and use it in GitHub Desktop.
a simple flashMessage function for web app notifications
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