Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
e99966b1
Commit
e99966b1
authored
Jul 21, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[chart] remove commented out & unnecessary loader code
parent
1fb5bf07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
100 deletions
+8
-100
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+1
-6
Common.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
+1
-6
Loader.purs
src/Gargantext/Hooks/Loader.purs
+6
-88
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
e99966b1
...
...
@@ -32,7 +32,7 @@ import Gargantext.Prelude
import Gargantext.Components.Table as T
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader, useLoaderWithCache
, useLoaderWithCache
API, HashedResponse(..))
import Gargantext.Hooks.Loader (useLoader, useLoaderWithCacheAPI, HashedResponse(..))
import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes
...
...
@@ -403,8 +403,6 @@ pageLayout props = R.createElement pageLayoutCpt props []
pageLayoutCpt :: R.Component PageLayoutProps
pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ =
-- useLoader path (loadPage session) paint
-- useLoaderWithCache path keyFunc (getPageHash session) (loadPage session) paint
useLoaderWithCacheAPI {
cacheEndpoint: getPageHash session
, handleResponse
...
...
@@ -417,9 +415,6 @@ pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
paint (Tuple count docs) = page params (newProps count) docs
newProps count = props { totalRecords = count }
-- keyFunc { corpusId, listId, nodeId, tabType } =
-- "page-" <> (show tabType) <> "-" <> (show corpusId) <> "-" <> (show nodeId) <> "-" <> (show listId)
mkRequest :: PageParams -> GUC.Request
mkRequest p@{ listId, nodeId, tabType } =
GUC.makeGetRequest session $ NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType) <> "&list=" <> (show listId)
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
View file @
e99966b1
...
...
@@ -9,7 +9,7 @@ import Reactix as R
import Gargantext.Prelude
import Gargantext.Components.Nodes.Corpus.Chart.Types (Reload, Path, Props, MetricsProps, ReloadPath)
import Gargantext.Hooks.Loader (HashedResponse, useLoader, useLoaderWithCache
, useLoaderWithCache
API)
import Gargantext.Hooks.Loader (HashedResponse, useLoader, useLoaderWithCacheAPI)
import Gargantext.Utils.Crypto (Hash)
import Gargantext.Sessions (Session)
import Gargantext.Utils.CacheAPI as GUC
...
...
@@ -50,11 +50,6 @@ metricsWithCacheLoadViewCpt :: forall res ret. DecodeJson res =>
metricsWithCacheLoadViewCpt = R.hooksComponent "G.C.N.C.C.metricsWithCacheLoadView" cpt
where
cpt { getMetricsHash, handleResponse, loaded, mkRequest, path, reload, session } _ = do
-- useLoaderWithCache (fst reload /\ path) (metricsKeyFunc keyFunc) (getMetricsHash session) (getMetrics session) $ \l ->
-- loaded session path reload l
-- metricsKeyFunc keyFunc st@(_ /\ { corpusId, listId, tabType }) =
-- "metrics-" <> (show tabType) <> "-" <> (show corpusId) <> "-" <> (show listId) <> "--" <> (keyFunc st)
useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session)
, handleResponse
, mkRequest
...
...
src/Gargantext/Hooks/Loader.purs
View file @
e99966b1
...
...
@@ -70,92 +70,9 @@ instance encodeHashedResponse :: EncodeJson a => EncodeJson (HashedResponse a) w
~> "value" := encodeJson value
~> jsonEmptyObject
useLoaderWithCache :: forall path st. Eq path => DecodeJson st => EncodeJson st =>
path
-> (path -> String)
-> (path -> Aff String)
-> (path -> Aff (HashedResponse st))
-> (st -> R.Element)
-> R.Hooks R.Element
useLoaderWithCache path keyFunc hashEndpoint loader render = do
state <- R.useState' Nothing
useCachedLoaderEffect { cacheEndpoint: hashEndpoint
, keyFunc
, loadRealData: loadRealData state
, path
, state }
pure $ maybe (loadingSpinner {}) render (fst state)
where
loadRealData :: R.State (Maybe st) -> String -> String -> WSS.Storage -> Aff Unit
loadRealData (_ /\ setState) key keyCache localStorage = do
--R2.affEffect "G.H.Loader.useCachedLoaderEffect" $ do
HashedResponse { hash, value: l } <- loader path
liftEffect $ do
let value = stringify $ encodeJson l
WSS.setItem key value localStorage
WSS.setItem keyCache hash localStorage
setState $ const $ Just l
pure unit
type CachedLoaderEffectProps cacheKey path st = (
cacheEndpoint :: path -> Aff cacheKey
, keyFunc :: path -> String
, loadRealData :: String -> String -> WSS.Storage -> Aff Unit
, path :: path
, state :: R.State (Maybe st)
)
useCachedLoaderEffect :: forall path st. Eq path => DecodeJson st => EncodeJson st =>
Record (CachedLoaderEffectProps String path st)
-> R.Hooks Unit
useCachedLoaderEffect { cacheEndpoint, keyFunc, loadRealData, path, state: state@(state' /\ setState) } = do
oPath <- R.useRef path
R.useEffect' $ do
if (R.readRef oPath == path) && (isJust state') then
pure unit
else do
R.setRef oPath path
let key = "loader--" <> (keyFunc path)
-- log2 "[useCachedLoader] key" key
let keyCache = key <> "-cache"
localStorage <- R2.getls
mState <- WSS.getItem key localStorage
mCache <- WSS.getItem keyCache localStorage
-- log2 "[useCachedLoader] mState" mState
launchAff_ $ do
case mState of
Nothing -> loadRealData key keyCache localStorage
Just stStr -> do
let parsed = parse stStr >>= decode
case parsed of
Left err -> do
-- liftEffect $ log2 "[useCachedLoader] err" err
loadRealData key keyCache localStorage
Right (st :: st) -> do
cacheReal <- cacheEndpoint path
-- liftEffect $ log2 "[useCachedLoader] cacheReal" cacheReal
case mCache of
Nothing -> do
-- liftEffect $ log2 "[useCachedLoader] no stored cache" Nothing
loadRealData key keyCache localStorage
Just cache -> do
-- liftEffect $ log2 "[useCachedLoader] stored cache" cache
if cache == cacheReal then
-- yay! cache hit!
liftEffect $ setState $ const $ Just st
else
loadRealData key keyCache localStorage
where
parse s = GU.mapLeft (\err -> "Error parsing serialised sessions:" <> show err) (jsonParser s)
decode j = GU.mapLeft (\err -> "Error decoding serialised sessions:" <> show err) (decodeJson j)
type LoaderWithCacheAPIProps path res ret =
( cacheEndpoint :: path -> Aff Hash
type LoaderWithCacheAPIProps path res ret = (
cacheEndpoint :: path -> Aff Hash
, handleResponse :: HashedResponse res -> ret
, mkRequest :: path -> GUC.Request
, path :: path
...
...
@@ -163,7 +80,8 @@ type LoaderWithCacheAPIProps path res ret =
)
useLoaderWithCacheAPI :: forall path res ret. Eq path => DecodeJson res =>
useLoaderWithCacheAPI :: forall path res ret.
Eq path => DecodeJson res =>
Record (LoaderWithCacheAPIProps path res ret)
-> R.Hooks R.Element
useLoaderWithCacheAPI { cacheEndpoint, handleResponse, mkRequest, path, renderer } = do
...
...
@@ -175,8 +93,8 @@ useLoaderWithCacheAPI { cacheEndpoint, handleResponse, mkRequest, path, renderer
, state }
pure $ maybe (loadingSpinner {}) renderer (fst state)
type LoaderWithCacheAPIEffectProps path res ret =
(
cacheEndpoint :: path -> Aff Hash
type LoaderWithCacheAPIEffectProps path res ret =
(
cacheEndpoint :: path -> Aff Hash
, handleResponse :: HashedResponse res -> ret
, mkRequest :: path -> GUC.Request
, path :: path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment