summaryrefslogtreecommitdiff
path: root/Hero/Node.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hero/Node.hs')
-rw-r--r--Hero/Node.hs20
1 files changed, 9 insertions, 11 deletions
diff --git a/Hero/Node.hs b/Hero/Node.hs
index e32cd59..55bc4b0 100644
--- a/Hero/Node.hs
+++ b/Hero/Node.hs
@@ -180,17 +180,13 @@ move (ScrollIntoView id) model = model <# do
move ValidateUserPassword model =
batchEff
model
- [doLogin, (SetComics </ fetchComics)]
+ [doLogin, pure FetchComics, pure <| ChangeURI discoverLink]
where
doLogin = do
- jslog "starting doLogin"
user <- getValue =<< Document.getElementById "user"
pass <- getValue =<< Document.getElementById "pass"
- jslog "sending login"
sendLogin (ms user) (ms pass) >>= \case
- Network.Success user -> do
- jslog "successful login"
- pure $ ChangeURI discoverLink
+ Network.Success _ -> pure NoOp
-- TODO: handle these error cases
Network.Loading -> pure NoOp
Network.Failure _ -> pure NoOp
@@ -201,9 +197,11 @@ fetchComics = Ajax.xhrByteString req /> Ajax.contents >>= \case
Nothing ->
pure $ Network.Failure "Could not fetch comics from server."
Just json ->
- pure $ Network.fromEither
- $ either (Left . ms) pure
- $ Aeson.eitherDecodeStrict json
+ json
+ |> Aeson.eitherDecodeStrict
+ |> either (Left . ms) pure
+ |> Network.fromEither
+ |> pure
where
req =
Ajax.Request
@@ -211,7 +209,7 @@ fetchComics = Ajax.xhrByteString req /> Ajax.contents >>= \case
Ajax.reqURI = "/api/comic", -- FIXME: can we replace this hardcoding?
Ajax.reqLogin = Nothing,
Ajax.reqHeaders = [],
- Ajax.reqWithCredentials = False,
+ Ajax.reqWithCredentials = True,
Ajax.reqData = Ajax.NoData
}
@@ -239,7 +237,7 @@ sendLogin u p = Ajax.xhrByteString req /> Ajax.contents >>= \case
[ ("Accept", "application/json"),
("Content-Type", "application/json")
],
- Ajax.reqWithCredentials = False,
+ Ajax.reqWithCredentials = True,
Ajax.reqData =
LoginForm (fromMisoString u) (fromMisoString p)
|> Aeson.encode