@@ -1,3 +1,4 @@
1+{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE GADTs #-}
3{-# LANGUAGE GADTs #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
@@ -14,6 +15,7 @@ import Control.Monad.Fix (MonadFix)
14import Data.Monoid (First(..), (<>))
15import Data.Monoid (First(..), (<>))
15import Data.Text (Text)
16import Data.Text (Text)
16import qualified Data.Text as T
17import qualified Data.Text as T
18+import qualified Data.Text.Encoding as T
17import GHC.TypeLits
19import GHC.TypeLits
18import Servant.API
20import Servant.API
@@ -43,7 +45,7 @@ runMulti :: forall t m. (SupportsServantReflex t m,
43runMulti = do
45runMulti = do
44 url <- baseUrlWidget
46 url <- baseUrlWidget
45 el "br" blank
47 el "br" blank
46− let (_ :<|> _ :<|> sayHi :<|> dbl :<|> _ :<|> _ ) =
48+ let (_ :<|> _ :<|> sayHi :<|> dbl :<|> _ :<|> _ :<|> _ :<|> _ ) =
47 clientA api (Proxy :: Proxy m) (Proxy :: Proxy []) (Proxy :: Proxy Int) url
49 clientA api (Proxy :: Proxy m) (Proxy :: Proxy []) (Proxy :: Proxy Int) url
49 num :: Dynamic t (Either Text Double) <- fmap (note "No read" . readMaybe . T.unpack) . value <$> textInput def
51 num :: Dynamic t (Either Text Double) <- fmap (note "No read" . readMaybe . T.unpack) . value <$> textInput def
@@ -66,9 +68,12 @@ runMulti = do
66 textInput def
68 textInput def
67 gust <- fmap (value) $ divClass "gusto-input" $ checkbox False def
69 gust <- fmap (value) $ divClass "gusto-input" $ checkbox False def
68 b <- button "Go"
70 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)
74+ dynText =<< holdDyn "Waiting" (T.pack . show . catMaybes .
75+ fmap reqSuccess <$> r')
71− dynText =<< holdDyn "Waiting" (T.pack . show . catMaybes . fmap reqSuccess <$> r')
@@ -91,7 +96,8 @@ run = mdo
91 el "br" (return ())
96 el "br" (return ())
93 -- Name the computed API client functions
98 -- 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) =
95 client api (Proxy :: Proxy m) (Proxy :: Proxy Int) url
101 client api (Proxy :: Proxy m) (Proxy :: Proxy Int) url
97 c2 = client (Proxy :: Proxy ComprehensiveAPI) (Proxy :: Proxy m) (Proxy :: Proxy ()) url -- Just make sure this compiles for now
103 c2 = client (Proxy :: Proxy ComprehensiveAPI) (Proxy :: Proxy m) (Proxy :: Proxy ()) url -- Just make sure this compiles for now
@@ -177,6 +183,18 @@ run = mdo
178 dynText =<< holdDyn "No Answer" (unAnswer <$> fmapMaybe reqSuccess rr)
184 dynText =<< holdDyn "No Answer" (unAnswer <$> fmapMaybe reqSuccess rr)
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)
180showXhrResponse :: XhrResponse -> Text
198showXhrResponse :: XhrResponse -> Text
181showXhrResponse (XhrResponse stat stattxt rbmay rtmay respHeaders) =
199showXhrResponse (XhrResponse stat stattxt rbmay rtmay respHeaders) =
182 T.unlines ["stat: " <> tShow stat
200 T.unlines ["stat: " <> tShow stat