@@ -1,3 +1,4 @@
1+{-# LANGUAGE DataKinds #-}
12{-# LANGUAGE FlexibleContexts #-}
23{-# LANGUAGE GADTs #-}
34{-# LANGUAGE OverloadedStrings #-}
@@ -14,6 +15,7 @@ import Control.Monad.Fix (MonadFix)
1415import Data.Monoid (First(..), (<>))
1516import Data.Text (Text)
1617import qualified Data.Text as T
18+import qualified Data.Text.Encoding as T
1719import GHC.TypeLits
1820import Servant.API
1921import API
@@ -43,7 +45,7 @@ runMulti :: forall t m. (SupportsServantReflex t m,
4345runMulti = do
4446 url <- baseUrlWidget
4547 el "br" blank
46− let (_ :<|> _ :<|> sayHi :<|> dbl :<|> _ :<|> _ ) =
48+ let (_ :<|> _ :<|> sayHi :<|> dbl :<|> _ :<|> _ :<|> _ :<|> _ ) =
4749 clientA api (Proxy :: Proxy m) (Proxy :: Proxy []) (Proxy :: Proxy Int) url
4850
4951 num :: Dynamic t (Either Text Double) <- fmap (note "No read" . readMaybe . T.unpack) . value <$> textInput def
@@ -66,9 +68,12 @@ runMulti = do
6668 textInput def
6769 gust <- fmap (value) $ divClass "gusto-input" $ checkbox False def
6870 b <- button "Go"
69− r' <- sayHi (fmap QParamSome <$> nms) (fmap (:[]) $ grts) (constDyn [True, False]) (1 <$ b)
71+ r' <- sayHi (fmap QParamSome <$> nms) (fmap (:[]) $ grts)
72+ (constDyn [True, False]) (1 <$ b)
73+
74+ dynText =<< holdDyn "Waiting" (T.pack . show . catMaybes .
75+ fmap reqSuccess <$> r')
7076
71− dynText =<< holdDyn "Waiting" (T.pack . show . catMaybes . fmap reqSuccess <$> r')
7277
7378 return ()
7479
@@ -91,7 +96,8 @@ run = mdo
9196 el "br" (return ())
9297
9398 -- Name the computed API client functions
94− let (getUnit :<|> getInt :<|> sayhi :<|> dbl :<|> multi :<|> qna :<|> doRaw) =
99+ let (getUnit :<|> getInt :<|> sayhi :<|> dbl
100+ :<|> multi :<|> qna :<|> secret :<|> doRaw) =
95101 client api (Proxy :: Proxy m) (Proxy :: Proxy Int) url
96102
97103 c2 = client (Proxy :: Proxy ComprehensiveAPI) (Proxy :: Proxy m) (Proxy :: Proxy ()) url -- Just make sure this compiles for now
@@ -177,6 +183,18 @@ run = mdo
177183 el "p" $
178184 dynText =<< holdDyn "No Answer" (unAnswer <$> fmapMaybe reqSuccess rr)
179185
186+ divClass "demo-group" $ do
187+ un <- fmap value $ text "Username" >> textArea def
188+ pw <- fmap value $ text "Unhidden PW" >> textArea def
189+ let ba :: Dynamic t (BasicAuthData ) = BasicAuthData
190+ <$> fmap T.encodeUtf8 un
191+ <*> fmap T.encodeUtf8 pw
192+ b <- button "Get secret"
193+ r <- secret (Just <$> ba) (0 <$ b)
194+ res <- holdDyn Nothing (reqSuccess <$> r)
195+ display res
196+
197+
180198showXhrResponse :: XhrResponse -> Text
181199showXhrResponse (XhrResponse stat stattxt rbmay rtmay respHeaders) =
182200 T.unlines ["stat: " <> tShow stat