{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
module Reflex.Bulmex.Load
( pageLoader
, prerenderLoad
, withReadyEvt
, postpone
, getReady
) where
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO)
import qualified Data.Text as Text
import Reflex
import Reflex.Bulmex.Event
import Reflex.Bulmex.Tag.Abstract
import Reflex.Dom.Builder.Class
import Reflex.Dom.Prerender
import qualified Reflex.Dom.Widget.Basic as Dom
import qualified Reflex.Tags as T
pageLoader :: DomBuilder t m => Text.Text -> m a -> m a
pageLoader = partialDiv "pageloader"
prerenderLoad :: (Prerender js t m, DomBuilder t m) => m () -> m ()
prerenderLoad spinner =
void $ prerender (T.divClass "prerender-load" $ spinner) Dom.blank
postpone :: (DomBuilder t m, MonadHold t m) => Event t () -> m () -> m ()
postpone evt m = holdEvent_ evt (const m)
getReady ::
( PostBuild t m
, PerformEvent t m
, TriggerEvent t m
, MonadIO (Performable m)
)
=> m (Event t ())
getReady = getPostBuild >>= delay 0
withReadyEvt ::
( PostBuild t m
, PerformEvent t m
, TriggerEvent t m
, MonadIO (Performable m)
)
=> m b
-> m (b, Event t ())
withReadyEvt mb = do
res <- mb
evt <- getReady
pure (res, evt)