diff options
Diffstat (limited to 'client/src/Main.hs')
-rw-r--r-- | client/src/Main.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/client/src/Main.hs b/client/src/Main.hs new file mode 100644 index 0000000..c71b0f0 --- /dev/null +++ b/client/src/Main.hs @@ -0,0 +1,39 @@ +module Main + ( main + ) where + +import qualified Data.Aeson as Aeson +import qualified Data.ByteString.Lazy as LB +import qualified Data.JSString.Text as Dom +import qualified Data.Text.Encoding as T +import qualified JSDOM as Dom +import qualified JSDOM.Generated.HTMLElement as Dom +import qualified JSDOM.Generated.NonElementParentNode as Dom +import JSDOM.Types (HTMLElement (..), JSM, + JSString) +import qualified JSDOM.Types as Dom +import Prelude hiding (error, init) + +import Common.Model (Init) +import qualified Common.Msg as Msg + +import qualified View.App as App + +main :: JSM () +main = do + initResult <- readInit + App.widget initResult + +readInit :: JSM (Maybe Init) +readInit = do + document <- Dom.currentDocumentUnchecked + initNode <- Dom.getElementById document ("init" :: JSString) + + case initNode of + Just node -> do + text <- Dom.textFromJSString <$> Dom.getInnerText (Dom.uncheckedCastTo HTMLElement node) + return $ case Aeson.decode (LB.fromStrict . T.encodeUtf8 $ text) of + Just init -> init + Nothing -> Nothing + _ -> + return Nothing |