Commit 9a5d4242 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REST] get function.

parent 309bb453
...@@ -32,6 +32,9 @@ import ReactDOM as RDOM ...@@ -32,6 +32,9 @@ import ReactDOM as RDOM
import Thermite (PerformAction, Render, Spec, cotransform, createReactSpec, defaultPerformAction, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, cotransform, createReactSpec, defaultPerformAction, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.REST (get)
main :: forall e. Eff (dom:: DOM, console :: CONSOLE, ajax :: AJAX | e) Unit main :: forall e. Eff (dom:: DOM, console :: CONSOLE, ajax :: AJAX | e) Unit
main = do main = do
case createReactSpec layoutDocview tdata of case createReactSpec layoutDocview tdata of
...@@ -143,7 +146,7 @@ performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePage ...@@ -143,7 +146,7 @@ performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePage
performAction (ChangePage p) _ _ = void (cotransform (\(TableData td) -> TableData $ td { currentPage = p} )) performAction (ChangePage p) _ _ = void (cotransform (\(TableData td) -> TableData $ td { currentPage = p} ))
performAction LoadData _ _ = void do performAction LoadData _ _ = void do
res <- lift $ loadData "http://localhost:8008/corpus/452132/facet/documents/table" res <- lift $ get "http://localhost:8008/corpus/452132/facet/documents/table"
--res <- lift $ loadData "http://localhost:8009/corpus/1/facet/documents/table" --res <- lift $ loadData "http://localhost:8009/corpus/1/facet/documents/table"
case res of case res of
Left err -> cotransform $ \(state) -> state Left err -> cotransform $ \(state) -> state
...@@ -380,20 +383,3 @@ showRow {row : (Corpus c), delete} = ...@@ -380,20 +383,3 @@ showRow {row : (Corpus c), delete} =
true -> "fas " true -> "fas "
false -> "far " false -> "far "
loadData :: forall eff. String -> Aff ( console :: CONSOLE, ajax :: AJAX| eff) (Either String (Array Response))
loadData url = do
affResp <- liftAff $ attempt $ affjax defaultRequest
{ method = Left GET
, url = url
, headers = [ ContentType applicationJSON
, Accept applicationJSON
-- , RequestHeader "Authorization" $ "Bearer " <> token
]
-- , content = Just $ encodeJson reqBody
}
case affResp of
Left err -> do
pure $ Left $ show err
Right a -> do
let res = decodeJson a.response
pure res
...@@ -15,14 +15,10 @@ import Data.Either (Either(..)) ...@@ -15,14 +15,10 @@ import Data.Either (Either(..))
import Network.HTTP.Affjax (AJAX, affjax, defaultRequest) import Network.HTTP.Affjax (AJAX, affjax, defaultRequest)
--loadData :: forall eff ajax a b. Bind ajax => MonadAff get :: forall eff t2 t31. DecodeJson t31 => String ->
-- ( ajax :: AJAX Aff ( console :: CONSOLE, ajax :: AJAX| eff)
-- , consolle :: CONSOLE (Either String t31)
-- | eff get url = do
-- )
-- ajax
-- => Respondable a => (a -> Either String b) -> String -> ajax (Either String b)
loadData f url = do
affResp <- liftAff $ attempt $ affjax defaultRequest affResp <- liftAff $ attempt $ affjax defaultRequest
{ method = Left GET { method = Left GET
, url = url , url = url
...@@ -35,5 +31,5 @@ loadData f url = do ...@@ -35,5 +31,5 @@ loadData f url = do
Left err -> do Left err -> do
pure $ Left $ show err pure $ Left $ show err
Right a -> do Right a -> do
let res = f a.response let res = decodeJson a.response
pure res pure res
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment