Commit 3d865bb1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[cacheApi] add raw fetch, fixes to Home/Public

In Home/Public error was thrown: <div> cannot be nested under <p>.
parent b5dbd5a3
...@@ -96,7 +96,7 @@ publicLayoutCpt = R.hooksComponent "[G.C.N.H.Public.publicLayout" cpt ...@@ -96,7 +96,7 @@ publicLayoutCpt = R.hooksComponent "[G.C.N.H.Public.publicLayout" cpt
[ H.h2 {} [H.text "Public Maps"] [ H.h2 {} [H.text "Public Maps"]
, H.p { className: "lead text-muted"} , H.p { className: "lead text-muted"}
[ H.text "Discover maps made with " [ H.text "Discover maps made with "
, H.div {className: "fa fa-heart"} [] , H.span {className: "fa fa-heart"} []
] ]
, H.p { className:"flex-space-around" } , H.p { className:"flex-space-around" }
[ H.a { className: "btn btn-primary my-2" [ H.a { className: "btn btn-primary my-2"
......
module Gargantext.Hooks.Loader where module Gargantext.Hooks.Loader where
import DOM.Simple.Console (log2)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (:=), (~>), jsonEmptyObject) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (:=), (~>), jsonEmptyObject)
import Data.Argonaut.Core (stringify) import Data.Argonaut.Core (stringify)
import Data.Argonaut.Parser (jsonParser) import Data.Argonaut.Parser (jsonParser)
...@@ -8,9 +7,14 @@ import Data.Either (Either(..)) ...@@ -8,9 +7,14 @@ import Data.Either (Either(..))
import Data.Maybe (Maybe(..), isJust, maybe) import Data.Maybe (Maybe(..), isJust, maybe)
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_, throwError) import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Exception (error) import Effect.Exception (error)
import Milkis as M
import Reactix as R
import Web.Storage.Storage as WSS
import Gargantext.Components.LoadingSpinner (loadingSpinner) import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Ends (class ToUrl, toUrl) import Gargantext.Ends (class ToUrl, toUrl)
import Gargantext.Prelude import Gargantext.Prelude
...@@ -18,9 +22,6 @@ import Gargantext.Utils.Crypto (Hash) ...@@ -18,9 +22,6 @@ import Gargantext.Utils.Crypto (Hash)
import Gargantext.Utils as GU import Gargantext.Utils as GU
import Gargantext.Utils.CacheAPI as GUC import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Milkis as M
import Reactix as R
import Web.Storage.Storage as WSS
useLoader :: forall path st. Eq path useLoader :: forall path st. Eq path
......
...@@ -36,3 +36,9 @@ exports._match = function(cache) { ...@@ -36,3 +36,9 @@ exports._match = function(cache) {
} }
} }
} }
exports._fetch = function(req) {
return function() {
return fetch(req);
}
}
...@@ -69,6 +69,7 @@ add cache req = toAffE $ _add cache req ...@@ -69,6 +69,7 @@ add cache req = toAffE $ _add cache req
match :: Cache -> Request -> Aff (Maybe M.Response) match :: Cache -> Request -> Aff (Maybe M.Response)
match cache req = do match cache req = do
res <- toAffE $ _match cache req res <- toAffE $ _match cache req
-- _match returns a null/undefined value when cache entity not found
case runExcept $ F.readNullOrUndefined res of case runExcept $ F.readNullOrUndefined res of
Left err -> throwError $ error $ show err Left err -> throwError $ error $ show err
Right v -> pure $ F.unsafeFromForeign <$> v Right v -> pure $ F.unsafeFromForeign <$> v
...@@ -96,15 +97,33 @@ cachedJson cache req = do ...@@ -96,15 +97,33 @@ cachedJson cache req = do
j <- M.json res j <- M.json res
case decodeJson (F.unsafeFromForeign j) of case decodeJson (F.unsafeFromForeign j) of
Left err -> throwError $ error $ "decodeJson affResp.body: " <> err Left err -> throwError $ error $ "[cachedJson] decodeJson affResp.body: " <> err
Right b -> pure b Right b -> pure b
delete :: Cache -> Request -> Aff Unit delete :: Cache -> Request -> Aff Unit
delete cache req = toAffE $ _delete cache req delete cache req = toAffE $ _delete cache req
-- No cache: raw API calls
fetch :: Request -> Aff M.Response
fetch req = do
res <- toAffE $ _fetch req
pure $ F.unsafeFromForeign res
pureJson :: forall a. DecodeJson a => Request -> Aff a
pureJson req = do
res <- fetch req
j <- M.json res
case decodeJson (F.unsafeFromForeign j) of
Left err -> throwError $ error $ "[pureJson] decodeJson affResp.body: " <> err
Right b -> pure b
foreign import _makeRequest :: forall options trash. Union options trash M.Options => foreign import _makeRequest :: forall options trash. Union options trash M.Options =>
M.URL -> { method :: M.Method, headers :: M.Headers | options } -> Request M.URL -> { method :: M.Method, headers :: M.Headers | options } -> Request
foreign import _openCache :: String -> Effect (Promise Cache) foreign import _openCache :: String -> Effect (Promise Cache)
foreign import _delete :: Cache -> Request -> Effect (Promise Unit) foreign import _delete :: Cache -> Request -> Effect (Promise Unit)
foreign import _add :: Cache -> Request -> Effect (Promise Unit) foreign import _add :: Cache -> Request -> Effect (Promise Unit)
foreign import _match :: Cache -> Request -> Effect (Promise F.Foreign) foreign import _match :: Cache -> Request -> Effect (Promise F.Foreign)
foreign import _fetch :: Request -> Effect (Promise F.Foreign)
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