packages feed

hanabi-dealer-0.10.1.0: Game/Hanabi/FFI.hs

{-# LANGUAGE OverloadedStrings #-}
module Game.Hanabi.FFI where

import Miso
import Control.Monad
import Control.Monad.IO.Class(liftIO)

foreign import javascript unsafe "var html = window.document.documentElement; $r = html.scrollHeight - html.clientHeight - (window.document.body.scrollTop || html.scrollTop);"
   getBottom :: IO Int

atTheBottom :: IO Bool
atTheBottom =  (<=0) <$> getBottom

windowBottomSub :: action    -- ^ ActionToBeTaken
                   -> action -- ^ NoAction
                   -> Sub action
windowBottomSub action noAction sink = windowAddEventListener "scroll" $ \_e -> do
  b <- atTheBottom
  liftIO $ sink $ if b then action else noAction