Commit 6e085c66 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[loader] some useLoaderBox refactoring

Just call useLoader under the hood.
parent 918c086d
......@@ -957,7 +957,7 @@ mainNgramsTableCacheOnCpt = here.component "mainNgramsTableCacheOn" cpt where
, spinnerClass: Nothing
}
versionEndpoint { defaultListId, path: { nodeId, tabType, session } } _ = get session $ Routes.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
errorHandler = logRESTError here "[mainNgramsTable]"
errorHandler = logRESTError here "[mainNgramsTableCacheOn]"
mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where
......@@ -994,7 +994,7 @@ mainNgramsTableCacheOffCpt = here.component "mainNgramsTableCacheOff" cpt where
, path
, render }
errorHandler = logRESTError here "[mainNgramsTable]"
errorHandler = logRESTError here "[mainNgramsTableCacheOff]"
-- NOTE With cache off
loader :: PageParams -> AffRESTError VersionedWithCountNgramsTable
......
......@@ -102,31 +102,9 @@ useLoaderBox :: forall path st. Eq path => Eq st
=> Record (UseLoaderBox path st)
-> R.Hooks R.Element
useLoaderBox { errorHandler, loader: loader', path, render } = do
state <- T.useBox Nothing
useLoaderBoxEffect { errorHandler, loader: loader', path, state: state }
pure $ loader { render, state } []
type UseLoaderBoxEffect path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> AffRESTError state
, path :: T.Box path
, state :: T.Box (Maybe state)
)
useLoaderBoxEffect :: forall st path. Eq path => Eq st
=> Record (UseLoaderBoxEffect path st)
-> R.Hooks Unit
useLoaderBoxEffect { errorHandler, loader: loader', path, state } = do
path' <- T.useLive T.unequal path
R.useEffect' $ do
R2.affEffect "G.H.Loader.useLoaderBoxEffect" $ do
l <- loader' path'
case l of
Left err -> liftEffect $ errorHandler err
Right l' -> liftEffect $ T.write_ (Just l') state
useLoader { errorHandler, loader: loader', path: path', render }
newtype HashedResponse a = HashedResponse { hash :: Hash, value :: a }
......
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