{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -- | App update logic module Biz.Ibb.Move ( move -- * Server interactions , fetchPeople ) where import Alpha import Biz.Ibb.Core as Core import Network.RemoteData import Data.Aeson import JavaScript.Web.XMLHttpRequest ( Request(..) , Method(GET) , RequestData(NoData) , contents , xhrByteString ) import Miso import Miso.String move :: Action -> Model -> Effect Action Model move Nop m = noEff m move (HandleRoute u) m = m { uri = u } <# pure Nop move (ChangeRoute u) m = m <# do pushURI u >> pure Nop move FetchPeople m = m <# (SetPeople pure $ Failure "could not read from server" Just a -> pure $ fromEither $ either (Left . ms) pure $ eitherDecodeStrict a where req = Request { reqMethod = GET -- FIXME: can replace this hardcoding with a function? , reqURI = "/api/people" , reqLogin = Nothing , reqHeaders = [] , reqWithCredentials = False , reqData = NoData }