@@ -2,16 +2,16 @@ module Components.Typeahead where
22
33import Prelude
44
5+ import Affjax (printError )
56import Affjax as AX
67import Affjax.ResponseFormat as AR
78import Components.Dropdown as D
8- import Data.Argonaut.Decode ((.:), decodeJson )
9+ import Data.Argonaut.Decode (decodeJson , printJsonDecodeError , (.:))
910import Data.Array (mapWithIndex , filter , (:), (!!), length , null , difference )
10- import Data.Foldable (for_ )
1111import Data.Bifunctor (lmap )
12+ import Data.Foldable (for_ )
1213import Data.Maybe (Maybe (..), maybe )
1314import Data.Monoid (guard )
14- import Data.Symbol (SProxy (..))
1515import Data.Time.Duration (Milliseconds (..))
1616import Data.Traversable (traverse )
1717import Effect.Aff (Aff )
@@ -23,6 +23,7 @@ import Internal.CSS (class_, classes_, whenElem)
2323import Internal.RemoteData as RD
2424import Select as S
2525import Select.Setters as SS
26+ import Type.Proxy (Proxy (..))
2627
2728type Slot =
2829 S.Slot Query ChildSlots Message
@@ -46,7 +47,7 @@ data Message
4647type ChildSlots =
4748 ( dropdown :: D.Slot Unit )
4849
49- component :: H.Component HH.HTML (S.Query Query ChildSlots ) Unit Message Aff
50+ component :: H.Component (S.Query Query ChildSlots ) Unit Message Aff
5051component = S .component (const input) $ S .defaultSpec
5152 { render = render
5253 , handleAction = handleAction
@@ -148,7 +149,7 @@ component = S.component (const input) $ S.defaultSpec
148149 closeButton item =
149150 HH .span
150151 [ class_ " Location__closeButton"
151- , HE .onClick \_ -> Just $ S.Action $ Remove item
152+ , HE .onClick \_ -> S.Action $ Remove item
152153 ]
153154 [ HH .text " ×" ]
154155
@@ -164,8 +165,8 @@ component = S.component (const input) $ S.defaultSpec
164165 renderDropdown = whenElem (st.visibility == S.On ) \_ ->
165166 HH .slot _dropdown unit D .component dropdownInput handler
166167 where
167- _dropdown = SProxy :: SProxy " dropdown"
168- handler msg = Just $ S.Action $ HandleDropdown msg
168+ _dropdown = Proxy :: Proxy " dropdown"
169+ handler msg = S.Action $ HandleDropdown msg
169170 dropdownInput = { items: [ " Earth" , " Mars" ], buttonLabel: " Human Planets" }
170171
171172 renderContainer = whenElem (st.visibility == S.On ) \_ ->
@@ -215,5 +216,8 @@ type Location =
215216searchLocations :: String -> Aff (RD.RemoteData String (Array Location ))
216217searchLocations search = do
217218 res <- AX .get AR .json (" https://swapi.co/api/planets/?search=" <> search)
218- let body = lmap AR .printResponseFormatError res.body
219- pure $ RD .fromEither $ traverse decodeJson =<< (_ .: " results" ) =<< decodeJson =<< body
219+ pure $ RD .fromEither $ traverse (lmap printJsonDecodeError <<< decodeJson)
220+ =<< (lmap printJsonDecodeError <<< (_ .: " results" ))
221+ =<< (lmap printJsonDecodeError <<< decodeJson)
222+ <<< _.body
223+ =<< (lmap printError res)
0 commit comments