Commit 15fe348f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] cache toggle button

parent 49ff5c12
......@@ -16,12 +16,51 @@
<link href="styles/Login.css" rel="stylesheet" type="text/css" />
<link href="styles/Tree.css" rel="stylesheet" type="text/css" />
<link href="styles/CodeEditor.css" rel="stylesheet" type="text/css" />
<link href="styles/Styles.css" rel="stylesheet" type="text/css" />
<link href="styles/range-slider.css" rel="stylesheet" type="text/css" />
<style>
.tree { margin: 0; padding: 0; border: 0; }
.tree LI { list-style: none; }
.tree UL { margin: 0 0 0 1.5em; border: 0; padding: 0; }
</style>
* {margin: 0; padding: 0; list-style: none;}
.tree ul li {
margin-left: 15px;
position: relative;
padding-left: 5px;
}
#toolbar {display : inline;}
#toolbar ul li {display : inline }
#toolbar ul li form {display : inline}
.tree { margin-top : 20px;}
.tree ul li::before {
content: " ";
position: absolute;
width: 1px;
background-color: #000;
top: 5px;
bottom: -12px;
left: -10px;
}
body > .tree ul > li:first-child::before {top: 12px;}
.tree ul li:not(:first-child):last-child::before {display: none;}
.tree ul li:only-child::before {
display: list-item;
content: " ";
position: absolute;
width: 1px;
background-color: "#000";
top: 5px;
bottom: 7px;
height: 7px;
left: -10px;
}
.tree ul li::after {
content: " ";
position: absolute;
left: -10px;
width: 10px;
height: 1px;
background-color: "#000";
top: 12px;
}
</style>
</head>
<body>
<div id="app" class ="container-fluid"></div>
......
......@@ -30,9 +30,11 @@ import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T
import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), read)
import Gargantext.Routes (SessionRoute(..)) as R
......@@ -483,6 +485,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ fst <$> rows
type MainNgramsTableProps =
( nodeId :: Int
-- ^ This node can be a corpus or contact.
, cacheState :: R.State NT.CacheState
, defaultListId :: Int
, tabType :: TabType
, session :: Session
......@@ -496,20 +499,30 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props []
mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = R2.hooksComponent thisModule "mainNgramsTable" cpt
where
cpt props@{nodeId, defaultListId, session, tabNgramType, tabType, withAutoUpdate} _ = do
cpt props@{ cacheState, defaultListId, nodeId, session, tabNgramType, tabType, withAutoUpdate} _ = do
let path = initialPageParams session nodeId [defaultListId] tabType
useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint props
, handleResponse
, mkRequest
, path
, renderer: \versioned -> mainNgramsTablePaint { path, tabNgramType, versioned, withAutoUpdate }
}
let render versioned = mainNgramsTablePaint { path, tabNgramType, versioned, withAutoUpdate }
case cacheState of
(NT.CacheOn /\ _) ->
useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint props
, handleResponse
, mkRequest
, path
, renderer: render
}
(NT.CacheOff /\ _) ->
useLoader path loader render
versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version
versionEndpoint { defaultListId, nodeId, session, tabType } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
loader :: PageParams -> Aff VersionedNgramsTable
loader path@{ listIds, nodeId, session, tabType } =
get session $ R.GetNgramsTableAll { listIds, tabType } (Just nodeId)
mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where
......@@ -523,14 +536,6 @@ mainNgramsTableCpt = R2.hooksComponent thisModule "mainNgramsTable" cpt
, termSizeFilter
} = R.GetNgramsTableAll { listIds
, tabType } (Just nodeId)
-- } = R.GetNgrams { limit
-- , listIds
-- , offset: Just offset
-- , orderBy: convOrderBy <$> orderBy
-- , searchQuery
-- , tabType
-- , termListFilter
-- , termSizeFilter } (Just nodeId)
handleResponse :: VersionedNgramsTable -> VersionedNgramsTable
handleResponse v = v
......
......@@ -17,6 +17,13 @@ import Gargantext.Components.NgramsTable.Core (Version(..), Versioned(..))
import Gargantext.Utils.CacheAPI as GUC
cacheName = "ngrams-cache-api-loader"
clearCache :: Unit -> Aff Unit
clearCache _ = GUC.delete $ GUC.CacheName cacheName
type LoaderWithCacheAPIProps path res ret = (
cacheEndpoint :: path -> Aff Version
, handleResponse :: Versioned res -> ret
......@@ -62,7 +69,6 @@ useCachedAPILoaderEffect { cacheEndpoint
else do
R.setRef oPath path
let cacheName = "ngrams-cache-api-loader"
let req = mkRequest path
-- log2 "[useCachedLoader] mState" mState
launchAff_ $ do
......@@ -77,7 +83,7 @@ useCachedAPILoaderEffect { cacheEndpoint
-- log "[useCachedAPILoaderEffect] versions dont match"
-- log2 "[useCachedAPILoaderEffect] cached version" version
-- log2 "[useCachedAPILoaderEffect] real version" cacheReal
_ <- GUC.delete cache req
_ <- GUC.deleteReq cache req
vr@(Versioned { version, "data": d }) <- GUC.cachedJson cache req
if version == cacheReal then
pure vr
......
......@@ -8,11 +8,13 @@ import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Prelude (bind, const, identity, pure, ($), (<$>), (<>))
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
......@@ -87,15 +89,22 @@ annuaireCpt = R2.hooksComponent thisModule "annuaire" cpt
cpt {session, path, info: info@(AnnuaireInfo {name, date: date'}), frontends} _ = do
pagePath <- R.useState' $ initialPagePath (fst path)
cacheState <- R.useState' NT.CacheOn
pure $ R.fragment
[ T.tableHeaderLayout headerProps
[ T.tableHeaderLayout { afterCacheStateChange: \_ -> pure unit
, cacheState
, date
, desc: name
, query: ""
, title: name
, user: "" }
, H.p {} []
, H.div {className: "col-md-3"}
[ H.text " Filter ", H.input { className: "form-control", style } ]
, H.br {}
, pageLayout { info, session, pagePath, frontends} ]
where
headerProps = { title: name, desc: name, query: "", date, user: ""}
date = "Last update: " <> date'
style = {width: "250px", display: "inline-block"}
initialPagePath nodeId = {nodeId, params: T.initialParams}
......
......@@ -18,6 +18,7 @@ import Reactix.DOM.HTML as H
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs as Tabs
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact(..), ContactData, ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, const, discard, pure, show, unit, ($), (+), (<$>), (<<<), (<>), (==))
......@@ -173,12 +174,14 @@ userLayoutWithKeyCpt = R2.hooksComponent thisModule "userLayoutWithKey" cpt
cpt { frontends, nodeId, session } _ = do
reload <- R.useState' 0
cacheState <- R.useState' NT.CacheOn
useLoader {nodeId, reload: fst reload, session} getContactWithReload $
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" }
[ display (fromMaybe "no name" name) (contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs {frontends, nodeId, contactData, session} ]
H.ul { className: "col-md-12 list-group" } [
display (fromMaybe "no name" name) (contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs { cacheState, contactData, frontends, nodeId, session }
]
where
onUpdateHyperdata :: R.State Int -> HyperdataUser -> Effect Unit
onUpdateHyperdata (_ /\ setReload) hd = do
......@@ -219,12 +222,14 @@ annuaireUserLayout props = R.createElement annuaireUserLayoutCpt props []
annuaireUserLayoutCpt :: R.Component AnnuaireLayoutProps
annuaireUserLayoutCpt = R2.hooksComponent thisModule "annuaireUserLayout" cpt
where
cpt {annuaireId, frontends, nodeId, session} _ = do
cpt { annuaireId, frontends, nodeId, session } _ = do
cacheState <- R.useState' NT.CacheOn
useLoader nodeId (getAnnuaireContact session annuaireId) $
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" }
[ display (fromMaybe "no name" name) (contactInfos hyperdata onUpdateHyperdata)
, Tabs.tabs {frontends, nodeId, contactData, session} ]
, Tabs.tabs { cacheState, contactData, frontends, nodeId, session } ]
where
onUpdateHyperdata :: HyperdataUser -> Effect Unit
......
......@@ -8,10 +8,12 @@ import Data.Maybe (Maybe(..))
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import Reactix as R
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData)
import Gargantext.Components.Nodes.Lists.Types as NTypes
import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session)
import Gargantext.Types (TabType(..), TabSubType(..), CTabNgramType(..), PTabNgramType(..))
......@@ -41,10 +43,12 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors
type TabsProps =
( nodeId :: Int
( cacheState :: R.State NTypes.CacheState
, contactData :: ContactData
, frontends :: Frontends
, session :: Session )
, nodeId :: Int
, session :: Session
)
tabs :: Record TabsProps -> R.Element
tabs props = R.createElement tabsCpt props []
......@@ -52,10 +56,10 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps
tabsCpt = R2.hooksComponent thisModule "tabs" cpt
where
cpt {frontends, nodeId, contactData: {defaultListId}, session} _ = do
cpt { cacheState, contactData: {defaultListId}, frontends, nodeId, session} _ = do
active <- R.useState' 0
pure $
Tab.tabs { tabs: tabs', selected: fst active }
Tab.tabs { selected: fst active, tabs: tabs' }
where
tabs' =
[ "Documents" /\ docs
......@@ -65,9 +69,9 @@ tabsCpt = R2.hooksComponent thisModule "tabs" cpt
, "Trash" /\ docs -- TODO pass-in trash mode
]
where
patentsView = {session, defaultListId, nodeId, mode: Patents}
booksView = {session, defaultListId, nodeId, mode: Books}
commView = {session, defaultListId, nodeId, mode: Communication}
patentsView = { cacheState, defaultListId, mode: Patents, nodeId, session }
booksView = { cacheState, defaultListId, mode: Books, nodeId, session }
commView = { cacheState, defaultListId, mode: Communication, nodeId, session }
chart = mempty
totalRecords = 4736 -- TODO
docs = DT.docViewLayout
......@@ -79,15 +83,24 @@ tabsCpt = R2.hooksComponent thisModule "tabs" cpt
type NgramsViewTabsProps =
( session :: Session
, mode :: Mode
( cacheState :: R.State NTypes.CacheState
, defaultListId :: Int
, nodeId :: Int )
, mode :: Mode
, nodeId :: Int
, session :: Session
)
ngramsView :: Record NgramsViewTabsProps -> R.Element
ngramsView {session,mode, defaultListId, nodeId} =
NT.mainNgramsTable
{ nodeId, defaultListId, tabType, session, tabNgramType, withAutoUpdate: false }
ngramsView { cacheState, defaultListId, mode, nodeId, session } =
NT.mainNgramsTable {
cacheState
, defaultListId
, nodeId
, tabType
, session
, tabNgramType
, withAutoUpdate: false
}
where
tabNgramType = modeTabType' mode
tabType = TabPairing $ TabNgramType $ modeTabType mode
module Gargantext.Components.Nodes.Lists where
import Effect.Aff (launchAff_)
import Reactix as R
------------------------------------------------------------------------
import Gargantext.Components.NgramsTable.Loader (clearCache)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Types (getCorpusInfo, CorpusInfo(..), Hyperdata(..))
import Gargantext.Components.Nodes.Lists.Tabs as Tabs
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as Table
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude
......@@ -46,13 +49,26 @@ listsLayoutWithKeyCpt = R2.hooksComponent thisModule "listsLayoutWithKey" cpt
cpt { nodeId, session } _ = do
let path = { nodeId, session }
cacheState <- R.useState' NT.CacheOn
useLoader path loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
let { date, hyperdata : Hyperdata h, name } = poly
CorpusInfo {desc,query,authors} = getCorpusInfo h.fields
in
R.fragment
[ Table.tableHeaderLayout
{ title: "Corpus " <> name, desc, query, user:authors, date }
, Tabs.tabs {session, corpusId, corpusData}]
R.fragment [
Table.tableHeaderLayout {
afterCacheStateChange: \_ -> launchAff_ $ clearCache unit
, cacheState
, date
, desc
, query
, title: "Corpus " <> name
, user: authors }
, Tabs.tabs {
cacheState
, corpusData
, corpusId
, session }
]
------------------------------------------------------------------------
......@@ -8,21 +8,23 @@ import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie, bar)
import Gargantext.Components.Nodes.Corpus.Chart.Tree (tree)
import Gargantext.Components.Nodes.Corpus.Chart (getChartFunction)
import Gargantext.Components.Nodes.Lists.Types as NTypes
import Gargantext.Components.Tab as Tab
import Gargantext.Sessions (Session)
import Gargantext.Types (ChartType(..), CTabNgramType(..), Mode(..), TabSubType(..), TabType(..), chartTypeFromString, modeTabType)
import Gargantext.Utils.Reactix as R2
thisModule = "Gargantext.Components.Nodes.Lists.Tabs"
type Props = ( session :: Session
type Props = ( cacheState :: R.State NTypes.CacheState
, corpusData :: CorpusData
, corpusId :: Int
, corpusData :: CorpusData
, session :: Session
)
tabs :: Record Props -> R.Element
......@@ -31,15 +33,16 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component Props
tabsCpt = R2.hooksComponent thisModule "tabs" cpt
where
cpt { corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do
cpt { cacheState, corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do
(selected /\ setSelected) <- R.useState' 0
pure $ Tab.tabs { selected, tabs: tabs' }
where
tabs' = [ "Authors" /\ view Authors
, "Institutes" /\ view Institutes
, "Sources" /\ view Sources
, "Terms" /\ view Terms ]
view mode = ngramsView { corpusData, corpusId, mode, session }
view mode = ngramsView { cacheState, corpusData, corpusId, mode, session }
type NgramsViewProps = ( mode :: Mode | Props )
......@@ -49,7 +52,8 @@ ngramsView props = R.createElement ngramsViewCpt props []
ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = R2.hooksComponent thisModule "ngramsView" cpt
where
cpt { corpusData: { defaultListId }
cpt { cacheState
, corpusData: { defaultListId }
, corpusId
, mode
, session } _ = do
......@@ -57,7 +61,8 @@ ngramsViewCpt = R2.hooksComponent thisModule "ngramsView" cpt
pure $ R.fragment
( charts tabNgramType chartType
<> [ NT.mainNgramsTable { defaultListId
<> [ NT.mainNgramsTable { cacheState
, defaultListId
, nodeId: corpusId
, session
, tabNgramType
......
module Gargantext.Components.Nodes.Lists.Types where
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Gargantext.Prelude
thisModule = "Gargantext.Components.Nodes.Lists.Types"
data CacheState = CacheOn | CacheOff
derive instance genericCacheState :: Generic CacheState _
instance eqCacheState :: Eq CacheState where
eq = genericEq
......@@ -14,6 +14,7 @@ import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..), getCorpusInfo, CorpusInfo(..))
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table
import Gargantext.Ends (Frontends)
......@@ -53,16 +54,25 @@ textsLayoutWithKeyCpt :: R.Component KeyProps
textsLayoutWithKeyCpt = R2.hooksComponent thisModule "textsLayoutWithKey" cpt
where
cpt { frontends, nodeId, session } _ = do
pure $ loader {session, nodeId} loadCorpusWithChild paint
where
paint corpusData@{corpusId, corpusNode, defaultListId} =
R.fragment [ Table.tableHeaderLayout headerProps, tabs' ]
where
NodePoly { name, date, hyperdata: Hyperdata h } = corpusNode
CorpusInfo {desc,query,authors} = getCorpusInfo h.fields
tabs' = tabs {session, corpusId, corpusData, frontends}
title = "Corpus " <> name
headerProps = { title, desc, query, date, user:authors }
cacheState <- R.useState' NT.CacheOn
pure $ loader {session, nodeId} loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode, defaultListId } -> do
let NodePoly { name, date, hyperdata: Hyperdata h } = corpusNode
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
tabs' = tabs { corpusData, corpusId, frontends, session }
title = "Corpus " <> name
R.fragment [
Table.tableHeaderLayout { afterCacheStateChange: \_ -> pure unit
, cacheState
, date
, desc
, query
, title
, user: authors }
, tabs'
]
data Mode = MoreLikeFav | MoreLikeTrash
......
......@@ -9,11 +9,14 @@ import Data.Maybe (Maybe(..))
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Search
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix (effectLink)
import Gargantext.Components.Search
thisModule = "Gargantext.Components.Table"
......@@ -87,10 +90,12 @@ stateParams {pageSize, page, orderBy, searchType} = {offset, limit, orderBy, sea
offset = limit * (page - 1)
type TableHeaderLayoutProps =
( title :: String
( afterCacheStateChange :: Unit -> Effect Unit
, cacheState :: R.State NT.CacheState
, date :: String
, desc :: String
, query :: String
, date :: String
, title :: String
, user :: String
)
......@@ -104,7 +109,7 @@ tableHeaderLayout props = R.createElement tableHeaderLayoutCpt props []
tableHeaderLayoutCpt :: R.Component TableHeaderLayoutProps
tableHeaderLayoutCpt = R2.hooksComponent thisModule "tableHeaderLayout" cpt
where
cpt {title, desc, query, date, user} _ =
cpt { afterCacheStateChange, cacheState, date, desc, query, title, user } _ =
pure $ R.fragment
[ R2.row
[ H.div {className: "col-md-3"} [ H.h3 {} [H.text title] ]
......@@ -115,27 +120,45 @@ tableHeaderLayoutCpt = R2.hooksComponent thisModule "tableHeaderLayout" cpt
[ H.div {className: "jumbotron1", style: {padding: "12px 0px 20px 12px"}}
[ H.div {className: "col-md-8 content"}
[ H.p {}
[ H.i {className: "glyphicon glyphicon-globe"} []
[ H.i {className: "fa fa-globe"} []
, H.text $ " " <> desc
]
]
, H.p {}
[ H.i {className: "glyphicon glyphicon-zoom-in"} []
[ H.i {className: "fa fa-search-plus"} []
, H.text $ " " <> query
]
, H.p { className: "cache-toggle"
, on: { click: cacheClick cacheState afterCacheStateChange } }
[ H.i {className: "fa " <> (cacheToggle cacheState)} []
, H.text $ cacheText cacheState
]
]
, H.div {className: "col-md-4 content"}
[ H.p {}
[ H.i {className: "glyphicon glyphicon-calendar"} []
[ H.i {className: "fa fa-calendar"} []
, H.text $ " " <> date
]
, H.p {}
[ H.i {className: "glyphicon glyphicon-user"} []
[ H.i {className: "fa fa-user"} []
, H.text $ " " <> user
]
]
]
]
]
cacheToggle (NT.CacheOn /\ _) = "fa-toggle-on"
cacheToggle (NT.CacheOff /\ _) = "fa-toggle-off"
cacheText (NT.CacheOn /\ _) = "Cache On"
cacheText (NT.CacheOff /\ _) = "Cache Off"
cacheClick (_ /\ setCacheState) after _ = do
setCacheState cacheStateToggle
after unit
cacheStateToggle NT.CacheOn = NT.CacheOff
cacheStateToggle NT.CacheOff = NT.CacheOn
table :: Record Props -> R.Element
table props = R.createElement tableCpt props []
......
......@@ -130,7 +130,7 @@ useCachedAPILoaderEffect { cacheEndpoint
val <- if hash == cacheReal then
pure hr
else do
_ <- GUC.delete cache req
_ <- GUC.deleteReq cache req
hr@(HashedResponse { hash, value }) <- GUC.cachedJson cache req
if hash == cacheReal then
pure hr
......
......@@ -13,7 +13,13 @@ exports._openCache = function(cacheName) {
}
}
exports._delete = function(cache) {
exports._delete = function(cacheName) {
return function() {
return caches.delete(cacheName);
}
}
exports._deleteReq = function(cache) {
return function(req) {
return function() {
return cache.delete(req);
......
......@@ -63,6 +63,9 @@ makeGetRequest session@(Session { token }) p = makeTokenRequest url (Just token)
openCache :: CacheName -> Aff Cache
openCache (CacheName cacheName) = toAffE $ _openCache cacheName
delete :: CacheName -> Aff Unit
delete (CacheName cacheName) = toAffE $ _delete cacheName
add :: Cache -> Request -> Aff Unit
add cache req = toAffE $ _add cache req
......@@ -100,8 +103,8 @@ cachedJson cache req = do
Left err -> throwError $ error $ "[cachedJson] decodeJson affResp.body: " <> show err
Right b -> pure b
delete :: Cache -> Request -> Aff Unit
delete cache req = toAffE $ _delete cache req
deleteReq :: Cache -> Request -> Aff Unit
deleteReq cache req = toAffE $ _deleteReq cache req
-- No cache: raw API calls
......@@ -123,7 +126,8 @@ pureJson req = do
foreign import _makeRequest :: forall options trash. Union options trash M.Options =>
M.URL -> { method :: M.Method, headers :: M.Headers | options } -> Request
foreign import _openCache :: String -> Effect (Promise Cache)
foreign import _delete :: Cache -> Request -> Effect (Promise Unit)
foreign import _delete :: String -> Effect (Promise Unit)
foreign import _deleteReq :: Cache -> Request -> Effect (Promise Unit)
foreign import _add :: Cache -> Request -> Effect (Promise Unit)
foreign import _match :: Cache -> Request -> Effect (Promise F.Foreign)
foreign import _fetch :: Request -> Effect (Promise F.Foreign)
......@@ -16,6 +16,7 @@
<link href="styles/Login.css" rel="stylesheet" type="text/css" />
<link href="styles/Tree.css" rel="stylesheet" type="text/css" />
<link href="styles/CodeEditor.css" rel="stylesheet" type="text/css" />
<link href="styles/Styles.css" rel="stylesheet" type="text/css" />
<link href="styles/range-slider.css" rel="stylesheet" type="text/css" />
<style>
* {margin: 0; padding: 0; list-style: none;}
......
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