Commit e9cb8c69 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toestand] cacheState is a T.Box now

parent 217a2f36
...@@ -11,14 +11,14 @@ import Data.Map as Map ...@@ -11,14 +11,14 @@ import Data.Map as Map
import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Tuple (fst) import Data.Tuple (fst)
import Effect (Effect) import Effect (Effect)
import Reactix as R
import Toestand as T
import Web.Storage.Storage as WSS
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils as GU import Gargantext.Utils as GU
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
import Reactix as R
import Toestand as T
import Web.Storage.Storage as WSS
localStorageKey :: String localStorageKey :: String
localStorageKey = "garg-async-tasks" localStorageKey = "garg-async-tasks"
...@@ -79,18 +79,18 @@ data Action = ...@@ -79,18 +79,18 @@ data Action =
action :: Record ReductorProps -> Action -> Effect (Record ReductorProps) action :: Record ReductorProps -> Action -> Effect (Record ReductorProps)
action p@{ reloadForest, storage } (Insert nodeId t) = do action p@{ reloadForest, storage } (Insert nodeId t) = do
_ <- GUR.bumpBox reloadForest _ <- T2.reload reloadForest
let newStorage = Map.alter (maybe (Just [t]) (\ts -> Just $ A.cons t ts)) nodeId storage let newStorage = Map.alter (maybe (Just [t]) (\ts -> Just $ A.cons t ts)) nodeId storage
pure $ p { storage = newStorage } pure $ p { storage = newStorage }
action p (Finish nodeId t) = do action p (Finish nodeId t) = do
action p (Remove nodeId t) action p (Remove nodeId t)
action p@{ reloadRoot, reloadForest, storage } (Remove nodeId t@(GT.AsyncTaskWithType { typ })) = do action p@{ reloadRoot, reloadForest, storage } (Remove nodeId t@(GT.AsyncTaskWithType { typ })) = do
_ <- if GT.asyncTaskTriggersAppReload typ then _ <- if GT.asyncTaskTriggersAppReload typ then
GUR.bumpBox reloadRoot T2.reload reloadRoot
else else
pure unit pure unit
_ <- if GT.asyncTaskTriggersTreeReload typ then _ <- if GT.asyncTaskTriggersTreeReload typ then
GUR.bumpBox reloadForest T2.reload reloadForest
else else
pure unit pure unit
let newStorage = Map.alter (maybe Nothing $ (\ts -> Just $ removeTaskFromList ts t)) nodeId storage let newStorage = Map.alter (maybe Nothing $ (\ts -> Just $ removeTaskFromList ts t)) nodeId storage
......
This diff is collapsed.
...@@ -82,7 +82,6 @@ forestCpt = here.component "forest" cpt where ...@@ -82,7 +82,6 @@ forestCpt = here.component "forest" cpt where
-- TODO fix tasks ref -- TODO fix tasks ref
-- R.useEffect' $ do -- R.useEffect' $ do
-- R.setRef tasks $ Just tasks' -- R.setRef tasks $ Just tasks'
-- GUR.initializeI reloadForest reload
R2.useCache R2.useCache
( frontends /\ route' /\ sessions' /\ handed' /\ forestOpen' ( frontends /\ route' /\ sessions' /\ handed' /\ forestOpen'
/\ reloadForest' /\ reloadRoot' /\ (fst tasks').storage ) /\ reloadForest' /\ reloadRoot' /\ (fst tasks').storage )
......
...@@ -39,7 +39,6 @@ import Gargantext.Sessions (OpenNodes, Session, Sessions, get) ...@@ -39,7 +39,6 @@ import Gargantext.Sessions (OpenNodes, Session, Sessions, get)
import Gargantext.Types as Types import Gargantext.Types as Types
import Gargantext.Utils.Range as Range import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
...@@ -58,7 +57,10 @@ type BaseProps = ...@@ -58,7 +57,10 @@ type BaseProps =
type LayoutLoaderProps = ( session :: R.Context Session | BaseProps ) type LayoutLoaderProps = ( session :: R.Context Session | BaseProps )
type LayoutProps = ( graphVersion :: GUR.ReloadS, session :: Session | BaseProps ) type LayoutProps =
( graphVersion :: T2.ReloadS
, session :: Session
| BaseProps )
type Props = type Props =
( graph :: SigmaxT.SGraph ( graph :: SigmaxT.SGraph
...@@ -74,7 +76,7 @@ explorerLayoutLoader = R.createElement explorerLayoutLoaderCpt ...@@ -74,7 +76,7 @@ explorerLayoutLoader = R.createElement explorerLayoutLoaderCpt
explorerLayoutLoaderCpt :: R.Component LayoutLoaderProps explorerLayoutLoaderCpt :: R.Component LayoutLoaderProps
explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where
cpt props _ = do cpt props _ = do
graphVersion <- GUR.new graphVersion <- T.useBox T2.newReload
session <- R.useContext props.session -- todo: ugh, props fiddling session <- R.useContext props.session -- todo: ugh, props fiddling
let base = RX.pick props :: Record BaseProps let base = RX.pick props :: Record BaseProps
let props' = Record.merge base { graphVersion, session } let props' = Record.merge base { graphVersion, session }
...@@ -86,7 +88,9 @@ explorerLayout = R.createElement explorerLayoutCpt ...@@ -86,7 +88,9 @@ explorerLayout = R.createElement explorerLayoutCpt
explorerLayoutCpt :: R.Component LayoutProps explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = here.component "explorerLayout" cpt where explorerLayoutCpt = here.component "explorerLayout" cpt where
cpt props@{ backend, graphId, graphVersion, session } _ = do cpt props@{ backend, graphId, graphVersion, session } _ = do
useLoader graphId (getNodes session graphVersion) handler graphVersion' <- T.useLive T.unequal graphVersion
useLoader graphId (getNodes session graphVersion') handler
where where
handler loaded = explorer (Record.merge props { graph, hyperdataGraph: loaded, mMetaData }) [] handler loaded = explorer (Record.merge props { graph, hyperdataGraph: loaded, mMetaData }) []
-- explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData }) -- explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData })
...@@ -116,6 +120,8 @@ explorerCpt = here.component "explorer" cpt ...@@ -116,6 +120,8 @@ explorerCpt = here.component "explorer" cpt
, tasks , tasks
} _ = do } _ = do
handed' <- T.useLive T.unequal handed handed' <- T.useLive T.unequal handed
graphVersion' <- T.useLive T.unequal graphVersion
graphVersionRef <- R.useRef graphVersion'
let startForceAtlas = maybe true (\(GET.MetaData { startForceAtlas: sfa }) -> sfa) mMetaData let startForceAtlas = maybe true (\(GET.MetaData { startForceAtlas: sfa }) -> sfa) mMetaData
...@@ -125,15 +131,12 @@ explorerCpt = here.component "explorer" cpt ...@@ -125,15 +131,12 @@ explorerCpt = here.component "explorer" cpt
dataRef <- R.useRef graph dataRef <- R.useRef graph
graphRef <- R.useRef null graphRef <- R.useRef null
graphVersionRef <- R.useRef (GUR.value graphVersion) reloadForest <- T.useBox T2.newReload
-- reloadForest <- T.useBox $ T2.Ready 0
reloadForest <- T.useBox 0
-- reloadForest <- GUR.newIInitialized reloadForest
controls <- Controls.useGraphControls { forceAtlasS controls <- Controls.useGraphControls { forceAtlasS
, graph , graph
, graphId , graphId
, hyperdataGraph , hyperdataGraph
, reloadForest: \_ -> GUR.bumpBox reloadForest , reloadForest: \_ -> T2.reload reloadForest
, session , session
} }
multiSelectEnabled' <- T.useLive T.unequal controls.multiSelectEnabled multiSelectEnabled' <- T.useLive T.unequal controls.multiSelectEnabled
...@@ -155,7 +158,7 @@ explorerCpt = here.component "explorer" cpt ...@@ -155,7 +158,7 @@ explorerCpt = here.component "explorer" cpt
let rSigma = R.readRef controls.sigmaRef let rSigma = R.readRef controls.sigmaRef
Sigmax.cleanupSigma rSigma "explorerCpt" Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph R.setRef dataRef graph
R.setRef graphVersionRef (GUR.value graphVersion) R.setRef graphVersionRef graphVersion'
-- Reinitialize bunch of state as well. -- Reinitialize bunch of state as well.
T.write_ SigmaxT.emptyNodeIds controls.removedNodeIds T.write_ SigmaxT.emptyNodeIds controls.removedNodeIds
T.write_ SigmaxT.emptyNodeIds controls.selectedNodeIds T.write_ SigmaxT.emptyNodeIds controls.selectedNodeIds
...@@ -277,7 +280,7 @@ type MSidebarProps = ...@@ -277,7 +280,7 @@ type MSidebarProps =
( frontends :: Frontends ( frontends :: Frontends
, graph :: SigmaxT.SGraph , graph :: SigmaxT.SGraph
, graphId :: GET.GraphId , graphId :: GET.GraphId
, graphVersion :: GUR.ReloadS , graphVersion :: T2.ReloadS
, reloadForest :: T.Box T2.Reload , reloadForest :: T.Box T2.Reload
, removedNodeIds :: T.Box SigmaxT.NodeIds , removedNodeIds :: T.Box SigmaxT.NodeIds
, selectedNodeIds :: T.Box SigmaxT.NodeIds , selectedNodeIds :: T.Box SigmaxT.NodeIds
...@@ -404,11 +407,11 @@ modeGraphType Types.Sources = "star" ...@@ -404,11 +407,11 @@ modeGraphType Types.Sources = "star"
modeGraphType Types.Terms = "def" modeGraphType Types.Terms = "def"
getNodes :: Session -> GUR.ReloadS -> GET.GraphId -> Aff GET.HyperdataGraph getNodes :: Session -> T2.Reload -> GET.GraphId -> Aff GET.HyperdataGraph
getNodes session graphVersion graphId = getNodes session graphVersion graphId =
get session $ NodeAPI Types.Graph get session $ NodeAPI Types.Graph
(Just graphId) (Just graphId)
("?version=" <> (show $ GUR.value graphVersion)) ("?version=" <> (show graphVersion))
type LiveProps = ( type LiveProps = (
edgeConfluence' :: Range.NumberRange edgeConfluence' :: Range.NumberRange
......
...@@ -36,7 +36,6 @@ import Gargantext.Hooks.Sigmax.Types as SigmaxT ...@@ -36,7 +36,6 @@ import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, NodeID, TabSubType(..), TabType(..), TermList(..), modeTabType) import Gargantext.Types (CTabNgramType, NodeID, TabSubType(..), TabType(..), TermList(..), modeTabType)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
...@@ -54,7 +53,7 @@ type Common = ( ...@@ -54,7 +53,7 @@ type Common = (
type Props = ( type Props = (
frontends :: Frontends frontends :: Frontends
, graph :: SigmaxT.SGraph , graph :: SigmaxT.SGraph
, graphVersion :: GUR.ReloadS , graphVersion :: T2.ReloadS
, showSidePanel :: T.Box GET.SidePanelState , showSidePanel :: T.Box GET.SidePanelState
| Common | Common
) )
...@@ -333,7 +332,7 @@ deleteNodes { graphId, metaData, nodes, session, termList, reloadForest } = do ...@@ -333,7 +332,7 @@ deleteNodes { graphId, metaData, nodes, session, termList, reloadForest } = do
case mPatch of case mPatch of
Nothing -> pure unit Nothing -> pure unit
Just (NTC.Versioned patch) -> do Just (NTC.Versioned patch) -> do
liftEffect $ GUR.bumpBox reloadForest liftEffect $ T2.reload reloadForest
-- Why is this called delete node? -- Why is this called delete node?
deleteNode :: TermList deleteNode :: TermList
......
...@@ -504,7 +504,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng ...@@ -504,7 +504,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng
type MainNgramsTableProps = ( type MainNgramsTableProps = (
cacheState :: R.State NT.CacheState cacheState :: T.Box NT.CacheState
, defaultListId :: Int , defaultListId :: Int
, nodeId :: Int , nodeId :: Int
-- ^ This node can be a corpus or contact. -- ^ This node can be a corpus or contact.
...@@ -521,25 +521,26 @@ mainNgramsTableCpt :: R.Component MainNgramsTableProps ...@@ -521,25 +521,26 @@ mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = here.component "mainNgramsTable" cpt mainNgramsTableCpt = here.component "mainNgramsTable" cpt
where where
cpt props@{ afterSync cpt props@{ afterSync
, reloadRoot
, tasks
, cacheState , cacheState
, defaultListId , defaultListId
, nodeId , nodeId
, path , path
, reloadForest
, reloadRoot
, session , session
, sidePanelTriggers , sidePanelTriggers
, tabNgramType , tabNgramType
, tabType , tabType
, reloadForest , tasks
, withAutoUpdate } _ = do , withAutoUpdate } _ = do
cacheState' <- T.useLive T.unequal cacheState
-- let path = initialPageParams session nodeId [defaultListId] tabType -- let path = initialPageParams session nodeId [defaultListId] tabType
case cacheState of case cacheState' of
(NT.CacheOn /\ _) -> do NT.CacheOn -> do
let render versioned = mainNgramsTablePaint { afterSync let render versioned = mainNgramsTablePaint { afterSync
, cacheState: fst cacheState , cacheState: cacheState'
, path: fst path , path: fst path
, reloadForest , reloadForest
, reloadRoot , reloadRoot
...@@ -555,10 +556,10 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt ...@@ -555,10 +556,10 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
, path: fst path , path: fst path
, renderer: render , renderer: render
} }
(NT.CacheOff /\ _) -> do NT.CacheOff -> do
-- path <- R.useState' path -- path <- R.useState' path
let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync
, cacheState: fst cacheState , cacheState: cacheState'
, path , path
, reloadForest , reloadForest
, reloadRoot , reloadRoot
......
...@@ -139,7 +139,6 @@ import Gargantext.Sessions (Session, get, post, put) ...@@ -139,7 +139,6 @@ import Gargantext.Sessions (Session, get, post, put)
import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..)) import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..))
import Gargantext.Utils.KarpRabin (indicesOfAny) import Gargantext.Utils.KarpRabin (indicesOfAny)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
...@@ -1191,7 +1190,7 @@ chartsAfterSync path' tasks nodeId reloadForest _ = do ...@@ -1191,7 +1190,7 @@ chartsAfterSync path' tasks nodeId reloadForest _ = do
Nothing -> log "[chartsAfterSync] tasks is Nothing" Nothing -> log "[chartsAfterSync] tasks is Nothing"
Just tasks' -> do Just tasks' -> do
snd tasks' (GAT.Insert nodeId task) -- *> T2.reload reloadForest snd tasks' (GAT.Insert nodeId task) -- *> T2.reload reloadForest
GUR.bumpBox reloadForest T2.reload reloadForest
postNgramsChartsAsync :: forall s. CoreParams s -> Aff AsyncTaskWithType postNgramsChartsAsync :: forall s. CoreParams s -> Aff AsyncTaskWithType
postNgramsChartsAsync { listIds, nodeId, session, tabType } = do postNgramsChartsAsync { listIds, nodeId, session, tabType } = do
......
...@@ -12,6 +12,8 @@ import Data.Tuple.Nested ((/\)) ...@@ -12,6 +12,8 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.NgramsTable.Loader (clearCache) import Gargantext.Components.NgramsTable.Loader (clearCache)
...@@ -92,17 +94,21 @@ annuaireCpt = here.component "annuaire" cpt ...@@ -92,17 +94,21 @@ annuaireCpt = here.component "annuaire" cpt
where where
cpt {session, path, info: info@(AnnuaireInfo {name, date: date'}), frontends} _ = do cpt {session, path, info: info@(AnnuaireInfo {name, date: date'}), frontends} _ = do
pagePath <- R.useState' $ initialPagePath (fst path) pagePath <- R.useState' $ initialPagePath (fst path)
cacheState <- R.useState' NT.CacheOff cacheState <- T.useBox NT.CacheOff
cacheState' <- T.useLive T.unequal cacheState
R.useEffectOnce' $ do
T.listen (\_ -> launchAff_ $ clearCache unit) cacheState
pure $ R.fragment pure $ R.fragment
[ T.tableHeaderLayout [ T.tableHeaderLayout
{ afterCacheStateChange: \_ -> launchAff_ $ clearCache unit { cacheState
, cacheState
, date , date
, desc: name , desc: name
, key: "annuaire-" <> (show $ fst cacheState) , key: "annuaire-" <> (show cacheState')
, query: "" , query: ""
, title: name , title: name
, user: "" } , user: "" } []
, H.p {} [] , H.p {} []
-- , H.div {className: "col-md-3"} [ H.text " Filter ", H.input { className: "form-control", style } ] -- , H.div {className: "col-md-3"} [ H.text " Filter ", H.input { className: "form-control", style } ]
, H.br {} , H.br {}
......
...@@ -51,7 +51,7 @@ modeTabType' Books = CTabAuthors ...@@ -51,7 +51,7 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors modeTabType' Communication = CTabAuthors
type TabsProps = type TabsProps =
( cacheState :: R.State LTypes.CacheState ( cacheState :: T.Box LTypes.CacheState
, contactData :: ContactData , contactData :: ContactData
, frontends :: Frontends , frontends :: Frontends
, nodeId :: Int , nodeId :: Int
...@@ -93,7 +93,7 @@ tabsCpt = here.component "tabs" cpt where ...@@ -93,7 +93,7 @@ tabsCpt = here.component "tabs" cpt where
} }
type DTCommon = type DTCommon =
( cacheState :: R.State LTypes.CacheState ( cacheState :: T.Box LTypes.CacheState
-- , contactData :: ContactData -- , contactData :: ContactData
, frontends :: Frontends , frontends :: Frontends
, nodeId :: Int , nodeId :: Int
...@@ -127,7 +127,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where ...@@ -127,7 +127,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
afterSync _ = pure unit afterSync _ = pure unit
type NTCommon = type NTCommon =
( cacheState :: R.State LTypes.CacheState ( cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int , defaultListId :: Int
, nodeId :: Int , nodeId :: Int
, reloadForest :: T.Box T2.Reload , reloadForest :: T.Box T2.Reload
......
...@@ -29,7 +29,6 @@ import Gargantext.Routes as Routes ...@@ -29,7 +29,6 @@ import Gargantext.Routes as Routes
import Gargantext.Sessions (WithSession, WithSessionContext, Session, get, put, sessionId) import Gargantext.Sessions (WithSession, WithSessionContext, Session, get, put, sessionId)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
...@@ -204,13 +203,14 @@ userLayoutWithKeyCpt :: R.Component KeyLayoutProps ...@@ -204,13 +203,14 @@ userLayoutWithKeyCpt :: R.Component KeyLayoutProps
userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt
where where
cpt { frontends, nodeId, reloadForest, reloadRoot, session, tasks } _ = do cpt { frontends, nodeId, reloadForest, reloadRoot, session, tasks } _ = do
reload <- GUR.new reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
cacheState <- R.useState' LT.CacheOn cacheState <- T.useBox LT.CacheOn
sidePanelTriggers <- LT.emptySidePanelTriggers sidePanelTriggers <- LT.emptySidePanelTriggers
useLoader {nodeId, reload: GUR.value reload, session} getUserWithReload $ useLoader {nodeId, reload: reload', session} getUserWithReload $
\contactData@{contactNode: Contact {name, hyperdata}} -> \contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" } [ H.ul { className: "col-md-12 list-group" } [
display { title: fromMaybe "no name" name } display { title: fromMaybe "no name" name }
...@@ -228,11 +228,11 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt ...@@ -228,11 +228,11 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt
} }
] ]
where where
onUpdateHyperdata :: GUR.ReloadS -> HyperdataUser -> Effect Unit onUpdateHyperdata :: T2.ReloadS -> HyperdataUser -> Effect Unit
onUpdateHyperdata reload hd = do onUpdateHyperdata reload hd = do
launchAff_ $ do launchAff_ $ do
_ <- saveContactHyperdata session nodeId hd _ <- saveContactHyperdata session nodeId hd
liftEffect $ GUR.bump reload liftEffect $ T2.reload reload
-- | toUrl to get data XXX -- | toUrl to get data XXX
getContact :: Session -> Int -> Aff ContactData getContact :: Session -> Int -> Aff ContactData
...@@ -247,7 +247,9 @@ getContact session id = do ...@@ -247,7 +247,9 @@ getContact session id = do
-- throwError $ error "Missing default list" -- throwError $ error "Missing default list"
pure {contactNode, defaultListId: 424242} pure {contactNode, defaultListId: 424242}
getUserWithReload :: {nodeId :: Int, reload :: GUR.Reload, session :: Session} -> Aff ContactData getUserWithReload :: { nodeId :: Int
, reload :: T2.Reload
, session :: Session} -> Aff ContactData
getUserWithReload {nodeId, session} = getContact session nodeId getUserWithReload {nodeId, session} = getContact session nodeId
saveContactHyperdata :: Session -> Int -> HyperdataUser -> Aff Int saveContactHyperdata :: Session -> Int -> HyperdataUser -> Aff Int
......
...@@ -183,7 +183,7 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where ...@@ -183,7 +183,7 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
, tasks } _ = do , tasks } _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
_ <- T.useLive T.unequal reload _ <- T.useLive T.unequal reload
cacheState <- R.useState' LT.CacheOn cacheState <- T.useBox LT.CacheOn
sidePanelTriggers <- LT.emptySidePanelTriggers sidePanelTriggers <- LT.emptySidePanelTriggers
useLoader nodeId (getAnnuaireContact session annuaireId) $ useLoader nodeId (getAnnuaireContact session annuaireId) $
\contactData@{contactNode: Contact' {name, hyperdata}} -> \contactData@{contactNode: Contact' {name, hyperdata}} ->
...@@ -191,8 +191,15 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where ...@@ -191,8 +191,15 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
[ display { title: fromMaybe "no name" name } [ display { title: fromMaybe "no name" name }
(contactInfos hyperdata (onUpdateHyperdata reload)) (contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs , Tabs.tabs
{ cacheState, contactData, frontends, nodeId, session { cacheState
, sidePanelTriggers, reloadForest, reloadRoot, tasks } ] , contactData
, frontends
, nodeId
, session
, sidePanelTriggers
, reloadForest
, reloadRoot
, tasks } ]
where where
onUpdateHyperdata :: T.Box T2.Reload -> HyperdataContact -> Effect Unit onUpdateHyperdata :: T.Box T2.Reload -> HyperdataContact -> Effect Unit
onUpdateHyperdata reload hd = onUpdateHyperdata reload hd =
......
...@@ -49,7 +49,7 @@ modeTabType' Books = CTabAuthors ...@@ -49,7 +49,7 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors modeTabType' Communication = CTabAuthors
type TabsProps = ( type TabsProps = (
cacheState :: R.State LTypes.CacheState cacheState :: T.Box LTypes.CacheState
, contactData :: ContactData' , contactData :: ContactData'
, frontends :: Frontends , frontends :: Frontends
, nodeId :: Int , nodeId :: Int
...@@ -131,7 +131,7 @@ tabsCpt = here.component "tabs" cpt ...@@ -131,7 +131,7 @@ tabsCpt = here.component "tabs" cpt
type NgramsViewTabsProps = ( type NgramsViewTabsProps = (
cacheState :: R.State LTypes.CacheState cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int , defaultListId :: Int
, mode :: Mode , mode :: Mode
, nodeId :: Int , nodeId :: Int
......
...@@ -18,6 +18,8 @@ import Effect.Class (liftEffect) ...@@ -18,6 +18,8 @@ import Effect.Class (liftEffect)
import Effect.Exception (error) import Effect.Exception (error)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.CodeEditor as CE import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.InputWithEnter (inputWithEnter) import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Node (NodePoly(..), HyperdataList) import Gargantext.Components.Node (NodePoly(..), HyperdataList)
...@@ -33,7 +35,7 @@ import Gargantext.Sessions (Session, get, put, sessionId) ...@@ -33,7 +35,7 @@ import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..), AffTableResult) import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Utils.Crypto as Crypto import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus" here = R2.here "Gargantext.Components.Nodes.Corpus"
...@@ -61,14 +63,14 @@ corpusLayoutWithKey props = R.createElement corpusLayoutWithKeyCpt props [] ...@@ -61,14 +63,14 @@ corpusLayoutWithKey props = R.createElement corpusLayoutWithKeyCpt props []
corpusLayoutWithKeyCpt :: R.Component KeyProps corpusLayoutWithKeyCpt :: R.Component KeyProps
corpusLayoutWithKeyCpt = here.component "corpusLayoutWithKey" cpt where corpusLayoutWithKeyCpt = here.component "corpusLayoutWithKey" cpt where
cpt { nodeId, session } _ = do cpt { nodeId, session } _ = do
reload <- GUR.new reload <- T.useBox T2.newReload
let reload' = GUR.value reload reload' <- T.useLive T.unequal reload
useLoader { nodeId, reload: reload', session } loadCorpusWithReload $ useLoader { nodeId, reload: reload', session } loadCorpusWithReload $
\corpus -> corpusLayoutView { corpus, nodeId, reload, session } \corpus -> corpusLayoutView { corpus, nodeId, reload, session }
type ViewProps = type ViewProps =
( corpus :: NodePoly Hyperdata ( corpus :: NodePoly Hyperdata
, reload :: GUR.ReloadS , reload :: T2.ReloadS
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
) )
...@@ -117,15 +119,15 @@ corpusLayoutViewCpt = here.component "corpusLayoutView" cpt ...@@ -117,15 +119,15 @@ corpusLayoutViewCpt = here.component "corpusLayoutView" cpt
saveEnabled fs (fsS /\ _) = if fs == fsS then "disabled" else "enabled" saveEnabled fs (fsS /\ _) = if fs == fsS then "disabled" else "enabled"
onClickSave :: forall e. { fields :: R.State FTFieldsWithIndex onClickSave :: forall e. { fields :: R.State FTFieldsWithIndex
, nodeId :: Int , nodeId :: Int
, reload :: GUR.ReloadS , reload :: T2.ReloadS
, session :: Session } -> e -> Effect Unit , session :: Session } -> e -> Effect Unit
onClickSave {fields: (fieldsS /\ _), nodeId, reload, session} _ = do onClickSave {fields: (fieldsS /\ _), nodeId, reload, session} _ = do
launchAff_ do launchAff_ do
saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS} saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
, nodeId , nodeId
, session } , session }
liftEffect $ GUR.bump reload liftEffect $ T2.reload reload
onClickAdd :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit onClickAdd :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit
onClickAdd (_ /\ setFieldsS) _ = do onClickAdd (_ /\ setFieldsS) _ = do
...@@ -144,16 +146,17 @@ fieldsCodeEditorCpt :: R.Component FieldsCodeEditorProps ...@@ -144,16 +146,17 @@ fieldsCodeEditorCpt :: R.Component FieldsCodeEditorProps
fieldsCodeEditorCpt = here.component "fieldsCodeEditorCpt" cpt fieldsCodeEditorCpt = here.component "fieldsCodeEditorCpt" cpt
where where
cpt {nodeId, fields: fS@(fields /\ _), session} _ = do cpt {nodeId, fields: fS@(fields /\ _), session} _ = do
masterKey <- GUR.new masterKey <- T.useBox T2.newReload
masterKey' <- T.useLive T.unequal masterKey
pure $ H.div {} $ List.toUnfoldable (editors masterKey) pure $ H.div {} $ List.toUnfoldable (editors masterKey masterKey')
where where
editors masterKey = editors masterKey masterKey' =
(\(Tuple idx field) -> (\(Tuple idx field) ->
fieldCodeEditorWrapper { canMoveDown: idx < (List.length fields - 1) fieldCodeEditorWrapper { canMoveDown: idx < (List.length fields - 1)
, canMoveUp: idx > 0 , canMoveUp: idx > 0
, field , field
, key: (show $ fst masterKey) <> "-" <> (show idx) , key: (show masterKey') <> "-" <> (show idx)
, onChange: onChange fS idx , onChange: onChange fS idx
, onMoveDown: onMoveDown masterKey fS idx , onMoveDown: onMoveDown masterKey fS idx
, onMoveUp: onMoveUp masterKey fS idx , onMoveUp: onMoveUp masterKey fS idx
...@@ -167,14 +170,14 @@ fieldsCodeEditorCpt = here.component "fieldsCodeEditorCpt" cpt ...@@ -167,14 +170,14 @@ fieldsCodeEditorCpt = here.component "fieldsCodeEditorCpt" cpt
fromMaybe fields $ fromMaybe fields $
List.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields List.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields
onMoveDown :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit onMoveDown :: T2.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveDown masterKey (_ /\ setFields) idx _ = do onMoveDown masterKey (_ /\ setFields) idx _ = do
GUR.bump masterKey T2.reload masterKey
setFields $ recomputeIndices <<< (GDA.swapList idx (idx + 1)) setFields $ recomputeIndices <<< (GDA.swapList idx (idx + 1))
onMoveUp :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit onMoveUp :: T2.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveUp masterKey (_ /\ setFields) idx _ = do onMoveUp masterKey (_ /\ setFields) idx _ = do
GUR.bump masterKey T2.reload masterKey
setFields $ recomputeIndices <<< (GDA.swapList idx (idx - 1)) setFields $ recomputeIndices <<< (GDA.swapList idx (idx - 1))
onRemove :: R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit onRemove :: R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
...@@ -392,7 +395,7 @@ loadCorpus' :: Record LoadProps -> Aff (NodePoly Hyperdata) ...@@ -392,7 +395,7 @@ loadCorpus' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) "" loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) ""
-- Just to make reloading effective -- Just to make reloading effective
loadCorpusWithReload :: {reload :: GUR.Reload | LoadProps} -> Aff (NodePoly Hyperdata) loadCorpusWithReload :: { reload :: T2.Reload | LoadProps } -> Aff (NodePoly Hyperdata)
loadCorpusWithReload {nodeId, session} = loadCorpus' {nodeId, session} loadCorpusWithReload {nodeId, session} = loadCorpus' {nodeId, session}
type SaveProps = ( type SaveProps = (
...@@ -443,7 +446,7 @@ loadCorpusWithChild { nodeId: childId, session } = do ...@@ -443,7 +446,7 @@ loadCorpusWithChild { nodeId: childId, session } = do
type LoadWithReloadProps = type LoadWithReloadProps =
( (
reload :: GUR.Reload reload :: T2.Reload
| LoadProps | LoadProps
) )
......
...@@ -5,6 +5,7 @@ import Data.Tuple (fst) ...@@ -5,6 +5,7 @@ import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Toestand as T
import Gargantext.Prelude import Gargantext.Prelude
...@@ -34,7 +35,9 @@ metricsLoadViewCpt :: forall a. R.Component (MetricsLoadViewProps a) ...@@ -34,7 +35,9 @@ metricsLoadViewCpt :: forall a. R.Component (MetricsLoadViewProps a)
metricsLoadViewCpt = here.component "metricsLoadView" cpt metricsLoadViewCpt = here.component "metricsLoadView" cpt
where where
cpt { getMetrics, loaded, path, reload, session } _ = do cpt { getMetrics, loaded, path, reload, session } _ = do
useLoader (fst reload /\ path) (getMetrics session) $ \l -> reload' <- T.useLive T.unequal reload
useLoader (reload' /\ path) (getMetrics session) $ \l ->
loaded { path, reload, session } l loaded { path, reload, session } l
type MetricsWithCacheLoadViewProps res ret = ( type MetricsWithCacheLoadViewProps res ret = (
...@@ -54,8 +57,10 @@ metricsWithCacheLoadViewCpt :: forall res ret. DecodeJson res => ...@@ -54,8 +57,10 @@ metricsWithCacheLoadViewCpt :: forall res ret. DecodeJson res =>
metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
where where
cpt { getMetricsHash, handleResponse, loaded, mkRequest, path, reload, session } _ = do cpt { getMetricsHash, handleResponse, loaded, mkRequest, path, reload, session } _ = do
reload' <- T.useLive T.unequal reload
useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session) useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session)
, handleResponse , handleResponse
, mkRequest , mkRequest
, path: (fst reload /\ path) , path: (reload' /\ path)
, renderer: loaded { path, reload, session } } , renderer: loaded { path, reload, session } }
...@@ -7,6 +7,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -7,6 +7,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Charts.Options.Color (grey) import Gargantext.Components.Charts.Options.Color (grey)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
...@@ -22,6 +23,7 @@ import Gargantext.Sessions (Session, get) ...@@ -22,6 +23,7 @@ import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..)) import Gargantext.Types (ChartType(..))
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 Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Histo" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Histo"
...@@ -87,7 +89,8 @@ histoCpt :: R.Component Props ...@@ -87,7 +89,8 @@ histoCpt :: R.Component Props
histoCpt = here.component "histo" cpt histoCpt = here.component "histo" cpt
where where
cpt { path, session } _ = do cpt { path, session } _ = do
reload <- R.useState' 0 reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
getMetricsHash getMetricsHash
, handleResponse , handleResponse
......
...@@ -12,6 +12,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -12,6 +12,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, yAxis') import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, yAxis')
import Gargantext.Components.Charts.Options.Type (xAxis) import Gargantext.Components.Charts.Options.Type (xAxis)
...@@ -28,6 +29,7 @@ import Gargantext.Sessions (Session, get) ...@@ -28,6 +29,7 @@ import Gargantext.Sessions (Session, get)
import Gargantext.Types (TermList(..)) import Gargantext.Types (TermList(..))
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 Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Metrics" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Metrics"
...@@ -122,7 +124,8 @@ metricsCpt :: R.Component Props ...@@ -122,7 +124,8 @@ metricsCpt :: R.Component Props
metricsCpt = here.component "etrics" cpt metricsCpt = here.component "etrics" cpt
where where
cpt {path, session} _ = do cpt {path, session} _ = do
reload <- R.useState' 0 reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
getMetricsHash getMetricsHash
, handleResponse , handleResponse
......
...@@ -12,6 +12,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -12,6 +12,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Charts.Options.Color (blue) import Gargantext.Components.Charts.Options.Color (blue)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
...@@ -27,6 +28,7 @@ import Gargantext.Sessions (Session, get) ...@@ -27,6 +28,7 @@ import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..)) import Gargantext.Types (ChartType(..))
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 Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Pie" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Pie"
...@@ -108,7 +110,7 @@ pieCpt :: R.Component Props ...@@ -108,7 +110,7 @@ pieCpt :: R.Component Props
pieCpt = here.component "pie" cpt pieCpt = here.component "pie" cpt
where where
cpt { path, session } _ = do cpt { path, session } _ = do
reload <- R.useState' 0 reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
getMetricsHash getMetricsHash
...@@ -136,7 +138,7 @@ barCpt :: R.Component Props ...@@ -136,7 +138,7 @@ barCpt :: R.Component Props
barCpt = here.component "bar" cpt barCpt = here.component "bar" cpt
where where
cpt {path, session} _ = do cpt {path, session} _ = do
reload <- R.useState' 0 reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
getMetricsHash getMetricsHash
......
...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis') import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
import Gargantext.Components.Charts.Options.Series (TreeNode, Trees(..), mkTree) import Gargantext.Components.Charts.Options.Series (TreeNode, Trees(..), mkTree)
...@@ -20,6 +21,7 @@ import Gargantext.Sessions (Session, get) ...@@ -20,6 +21,7 @@ import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..)) import Gargantext.Types (ChartType(..))
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 Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Tree" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Tree"
...@@ -78,7 +80,7 @@ treeCpt :: R.Component Props ...@@ -78,7 +80,7 @@ treeCpt :: R.Component Props
treeCpt = here.component "tree" cpt treeCpt = here.component "tree" cpt
where where
cpt {path, session} _ = do cpt {path, session} _ = do
reload <- R.useState' 0 reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
getMetricsHash getMetricsHash
, handleResponse , handleResponse
......
...@@ -5,7 +5,7 @@ import Data.Tuple (Tuple) ...@@ -5,7 +5,7 @@ import Data.Tuple (Tuple)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (TabType) import Gargantext.Types (TabType)
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Toestand as T2
type Path = ( type Path = (
corpusId :: Int corpusId :: Int
...@@ -20,8 +20,8 @@ type Props = ( ...@@ -20,8 +20,8 @@ type Props = (
) )
type MetricsProps = ( type MetricsProps = (
reload :: GUR.ReloadS reload :: T2.ReloadS
| Props | Props
) )
type ReloadPath = Tuple GUR.Reload (Record Path) type ReloadPath = Tuple T2.Reload (Record Path)
...@@ -13,21 +13,21 @@ import Gargantext.Components.Nodes.Corpus.Chart.Types (Path) ...@@ -13,21 +13,21 @@ import Gargantext.Components.Nodes.Corpus.Chart.Types (Path)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types as T import Gargantext.Types as T
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Utils" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Utils"
reloadButtonWrap :: GUR.ReloadS -> R.Element -> R.Element reloadButtonWrap :: T2.ReloadS -> R.Element -> R.Element
reloadButtonWrap setReload el = H.div {} [ reloadButtonWrap setReload el = H.div {} [
reloadButton setReload reloadButton setReload
, el , el
] ]
reloadButton :: GUR.ReloadS -> R.Element reloadButton :: T2.ReloadS -> R.Element
reloadButton reloadS = H.a { className, on: { click }, title: "Reload" } [] where reloadButton reloadS = H.a { className, on: { click }, title: "Reload" } [] where
className = "reload-btn fa fa-refresh" className = "reload-btn fa fa-refresh"
click _ = GUR.bump reloadS click _ = T2.reload reloadS
mNgramsTypeFromTabType :: T.TabType -> Maybe T.CTabNgramType mNgramsTypeFromTabType :: T.TabType -> Maybe T.CTabNgramType
...@@ -38,9 +38,9 @@ mNgramsTypeFromTabType _ = Nothing ...@@ -38,9 +38,9 @@ mNgramsTypeFromTabType _ = Nothing
type ChartUpdateButtonProps = type ChartUpdateButtonProps =
( chartType :: T.ChartType ( chartType :: T.ChartType
, path :: Record Path , path :: Record Path
, reload :: GUR.ReloadS , reload :: T2.ReloadS
, session :: Session , session :: Session
) )
chartUpdateButton :: Record ChartUpdateButtonProps -> R.Element chartUpdateButton :: Record ChartUpdateButtonProps -> R.Element
...@@ -59,5 +59,5 @@ chartUpdateButtonCpt = here.component "chartUpdateButton" cpt where ...@@ -59,5 +59,5 @@ chartUpdateButtonCpt = here.component "chartUpdateButton" cpt where
case mNgramsTypeFromTabType tabType of case mNgramsTypeFromTabType tabType of
Just ngramsType -> do Just ngramsType -> do
_ <- recomputeChart session chartType ngramsType corpusId listId _ <- recomputeChart session chartType ngramsType corpusId listId
liftEffect $ GUR.bump reload liftEffect $ T2.reload reload
Nothing -> pure unit Nothing -> pure unit
...@@ -13,6 +13,8 @@ import Effect.Aff (launchAff_) ...@@ -13,6 +13,8 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Nodes.Corpus (fieldsCodeEditor) import Gargantext.Components.Nodes.Corpus (fieldsCodeEditor)
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Dashboard.Types as DT import Gargantext.Components.Nodes.Dashboard.Types as DT
...@@ -21,7 +23,7 @@ import Gargantext.Hooks.Loader (useLoader) ...@@ -21,7 +23,7 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session, sessionId) import Gargantext.Sessions (Session, sessionId)
import Gargantext.Types (NodeID) import Gargantext.Types (NodeID)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Dashboard" here = R2.here "Gargantext.Components.Nodes.Corpus.Dashboard"
...@@ -50,9 +52,10 @@ dashboardLayoutWithKeyCpt :: R.Component KeyProps ...@@ -50,9 +52,10 @@ dashboardLayoutWithKeyCpt :: R.Component KeyProps
dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
where where
cpt { nodeId, session } _ = do cpt { nodeId, session } _ = do
reload <- GUR.new reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader {nodeId, reload: GUR.value reload, session} DT.loadDashboardWithReload $ useLoader {nodeId, reload: reload', session} DT.loadDashboardWithReload $
\dashboardData@{hyperdata: DT.Hyperdata h, parentId} -> do \dashboardData@{hyperdata: DT.Hyperdata h, parentId} -> do
let { charts, fields } = h let { charts, fields } = h
dashboardLayoutLoaded { charts dashboardLayoutLoaded { charts
...@@ -63,14 +66,14 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt ...@@ -63,14 +66,14 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
, onChange: onChange nodeId reload (DT.Hyperdata h) , onChange: onChange nodeId reload (DT.Hyperdata h)
, session } [] , session } []
where where
onChange :: NodeID -> GUR.ReloadS -> DT.Hyperdata -> { charts :: Array P.PredefinedChart onChange :: NodeID -> T2.ReloadS -> DT.Hyperdata -> { charts :: Array P.PredefinedChart
, fields :: List.List FTField } -> Effect Unit , fields :: List.List FTField } -> Effect Unit
onChange nodeId' reload (DT.Hyperdata h) { charts, fields } = do onChange nodeId' reload (DT.Hyperdata h) { charts, fields } = do
launchAff_ do launchAff_ do
DT.saveDashboard { hyperdata: DT.Hyperdata $ h { charts = charts, fields = fields } DT.saveDashboard { hyperdata: DT.Hyperdata $ h { charts = charts, fields = fields }
, nodeId:nodeId' , nodeId:nodeId'
, session } , session }
liftEffect $ GUR.bump reload liftEffect $ T2.reload reload
type LoadedProps = type LoadedProps =
( charts :: Array P.PredefinedChart ( charts :: Array P.PredefinedChart
......
...@@ -8,6 +8,7 @@ import Data.Generic.Rep.Show (genericShow) ...@@ -8,6 +8,7 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Toestand as T
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
...@@ -17,7 +18,7 @@ import Gargantext.Sessions (Session, get, sessionId) ...@@ -17,7 +18,7 @@ import Gargantext.Sessions (Session, get, sessionId)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Argonaut (genericSumEncodeJson) import Gargantext.Utils.Argonaut (genericSumEncodeJson)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Frame" here = R2.here "Gargantext.Components.Nodes.Frame"
...@@ -72,13 +73,14 @@ frameLayoutWithKey props = R.createElement frameLayoutWithKeyCpt props [] ...@@ -72,13 +73,14 @@ frameLayoutWithKey props = R.createElement frameLayoutWithKeyCpt props []
frameLayoutWithKeyCpt :: R.Component KeyProps frameLayoutWithKeyCpt :: R.Component KeyProps
frameLayoutWithKeyCpt = here.component "frameLayoutWithKey" cpt where frameLayoutWithKeyCpt = here.component "frameLayoutWithKey" cpt where
cpt { nodeId, session, nodeType} _ = do cpt { nodeId, session, nodeType} _ = do
reload <- GUR.new reload <- T.useBox T2.newReload
useLoader {nodeId, reload: GUR.value reload, session} loadframeWithReload $ reload' <- T.useLive T.unequal reload
useLoader {nodeId, reload: reload', session} loadframeWithReload $
\frame -> frameLayoutView {frame, nodeId, reload, session, nodeType} \frame -> frameLayoutView {frame, nodeId, reload, session, nodeType}
type ViewProps = type ViewProps =
( frame :: NodePoly Hyperdata ( frame :: NodePoly Hyperdata
, reload :: GUR.ReloadS , reload :: T2.ReloadS
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
, nodeType :: NodeType , nodeType :: NodeType
...@@ -107,7 +109,9 @@ frameLayoutViewCpt = here.component "frameLayoutView" cpt ...@@ -107,7 +109,9 @@ frameLayoutViewCpt = here.component "frameLayoutView" cpt
type LoadProps = ( nodeId :: Int, session :: Session ) type LoadProps = ( nodeId :: Int, session :: Session )
type ReloadProps = ( nodeId :: Int, session :: Session, reload :: GUR.Reload ) type ReloadProps = ( nodeId :: Int
, reload :: T2.Reload
, session :: Session )
loadframe' :: Record LoadProps -> Aff (NodePoly Hyperdata) loadframe' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadframe' { nodeId, session } = get session $ NodeAPI Node (Just nodeId) "" loadframe' { nodeId, session } = get session $ NodeAPI Node (Just nodeId) ""
......
...@@ -120,7 +120,11 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where ...@@ -120,7 +120,11 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
cpt { controls, nodeId, reloadForest, reloadRoot, session, sessionUpdate, tasks } _ = do cpt { controls, nodeId, reloadForest, reloadRoot, session, sessionUpdate, tasks } _ = do
let path = { nodeId, session } let path = { nodeId, session }
cacheState <- R.useState' $ getCacheState CacheOn session nodeId cacheState <- T.useBox $ getCacheState CacheOn session nodeId
cacheState' <- T.useLive T.unequal cacheState
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
useLoader path loadCorpusWithChild $ useLoader path loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } -> \corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
...@@ -129,19 +133,18 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where ...@@ -129,19 +133,18 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
in in
R.fragment [ R.fragment [
Table.tableHeaderLayout { Table.tableHeaderLayout {
afterCacheStateChange cacheState
, cacheState
, date , date
, desc , desc
, key: "listsLayoutWithKey-header-" <> (show $ fst cacheState) , key: "listsLayoutWithKey-header-" <> (show cacheState')
, query , query
, title: "Corpus " <> name , title: "Corpus " <> name
, user: authors } , user: authors } []
, Tabs.tabs { , Tabs.tabs {
cacheState cacheState
, corpusData , corpusData
, corpusId , corpusId
, key: "listsLayoutWithKey-tabs-" <> (show $ fst cacheState) , key: "listsLayoutWithKey-tabs-" <> (show cacheState')
, reloadForest , reloadForest
, reloadRoot , reloadRoot
, session , session
......
...@@ -27,14 +27,13 @@ import Gargantext.Sessions (Session) ...@@ -27,14 +27,13 @@ import Gargantext.Sessions (Session)
import Gargantext.Types import Gargantext.Types
( ChartType(..), CTabNgramType(..), Mode(..), TabSubType(..), TabType(..), modeTabType ) ( ChartType(..), CTabNgramType(..), Mode(..), TabSubType(..), TabType(..), modeTabType )
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Lists.Tabs" here = R2.here "Gargantext.Components.Nodes.Lists.Tabs"
type Props = ( type Props = (
cacheState :: R.State CacheState cacheState :: T.Box CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: Int , corpusId :: Int
, reloadForest :: T.Box T2.Reload , reloadForest :: T.Box T2.Reload
...@@ -69,10 +68,17 @@ ngramsView props = R.createElement ngramsViewCpt props [] ...@@ -69,10 +68,17 @@ ngramsView props = R.createElement ngramsViewCpt props []
ngramsViewCpt :: R.Component NgramsViewProps ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = here.component "ngramsView" cpt where ngramsViewCpt = here.component "ngramsView" cpt where
cpt props@{ reloadRoot, tasks, cacheState, corpusData: { defaultListId } cpt props@{ cacheState
, corpusId, mode, session, sidePanelTriggers, reloadForest } _ = do , corpusData: { defaultListId }
, corpusId
, reloadForest
, reloadRoot
, mode
, session
, sidePanelTriggers
, tasks } _ = do
chartType <- R.useState' Histo chartType <- R.useState' Histo
chartsReload <- GUR.new chartsReload <- T.useBox T2.newReload
path <- R.useState' $ NTC.initialPageParams props.session initialPath.corpusId [initialPath.listId] initialPath.tabType path <- R.useState' $ NTC.initialPageParams props.session initialPath.corpusId [initialPath.listId] initialPath.tabType
let listId' = fromMaybe defaultListId $ A.head (fst path).listIds let listId' = fromMaybe defaultListId $ A.head (fst path).listIds
let path' = { let path' = {
...@@ -91,17 +97,17 @@ ngramsViewCpt = here.component "ngramsView" cpt where ...@@ -91,17 +97,17 @@ ngramsViewCpt = here.component "ngramsView" cpt where
pure $ R.fragment pure $ R.fragment
( charts chartParams tabNgramType chartType chartsReload ( charts chartParams tabNgramType chartType chartsReload
<> [ NT.mainNgramsTable { afterSync: afterSync chartsReload <> [ NT.mainNgramsTable { afterSync: afterSync chartsReload
, reloadRoot
, tasks
, cacheState , cacheState
, defaultListId , defaultListId
, nodeId: corpusId , nodeId: corpusId
, path , path
, reloadForest
, reloadRoot
, session , session
, sidePanelTriggers , sidePanelTriggers
, tabNgramType , tabNgramType
, tabType , tabType
, reloadForest , tasks
, withAutoUpdate: false , withAutoUpdate: false
} [] } []
] ]
...@@ -114,7 +120,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where ...@@ -114,7 +120,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
-- should be recomputed already -- should be recomputed already
-- We just refresh it -- We just refresh it
-- _ <- recomputeChart session chartType ngramsType corpusId listId -- _ <- recomputeChart session chartType ngramsType corpusId listId
liftEffect $ GUR.bump chartsReload liftEffect $ T2.reload chartsReload
Nothing -> pure unit Nothing -> pure unit
tabNgramType = modeTabType mode tabNgramType = modeTabType mode
......
...@@ -14,6 +14,7 @@ import Reactix as R ...@@ -14,6 +14,7 @@ import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
import Record.Extra as REX import Record.Extra as REX
import Toestand as T
import Gargantext.Components.DocsTable as DT import Gargantext.Components.DocsTable as DT
import Gargantext.Components.Forest as Forest import Gargantext.Components.Forest as Forest
...@@ -140,7 +141,11 @@ textsLayoutWithKeyCpt :: R.Component KeyProps ...@@ -140,7 +141,11 @@ textsLayoutWithKeyCpt :: R.Component KeyProps
textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
where where
cpt { controls, frontends, nodeId, session } _children = do cpt { controls, frontends, nodeId, session } _children = do
cacheState <- R.useState' $ getCacheState NT.CacheOff session nodeId cacheState <- T.useBox $ getCacheState NT.CacheOff session nodeId
cacheState' <- T.useLive T.unequal cacheState
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
pure $ loader { nodeId, session } loadCorpusWithChild $ pure $ loader { nodeId, session } loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode, defaultListId } -> do \corpusData@{ corpusId, corpusNode, defaultListId } -> do
...@@ -148,14 +153,13 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt ...@@ -148,14 +153,13 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
title = "Corpus " <> name title = "Corpus " <> name
R.fragment R.fragment
[ Table.tableHeaderLayout { afterCacheStateChange [ Table.tableHeaderLayout { cacheState
, cacheState
, date , date
, desc , desc
, query , query
, title , title
, user: authors , user: authors
, key: "textsLayoutWithKey-" <> (show $ fst cacheState) } , key: "textsLayoutWithKey-" <> (show cacheState') } []
, tabs { cacheState , tabs { cacheState
, corpusData , corpusData
, corpusId , corpusId
...@@ -184,7 +188,7 @@ modeTabType MoreLikeFav = CTabAuthors -- TODO ...@@ -184,7 +188,7 @@ modeTabType MoreLikeFav = CTabAuthors -- TODO
modeTabType MoreLikeTrash = CTabSources -- TODO modeTabType MoreLikeTrash = CTabSources -- TODO
type TabsProps = type TabsProps =
( cacheState :: R.State NT.CacheState ( cacheState :: T.Box NT.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: NodeID , corpusId :: NodeID
, frontends :: Frontends , frontends :: Frontends
...@@ -232,7 +236,7 @@ tabsCpt = here.component "tabs" cpt ...@@ -232,7 +236,7 @@ tabsCpt = here.component "tabs" cpt
, sidePanelTriggers } [] , sidePanelTriggers } []
type DocViewProps a = ( type DocViewProps a = (
cacheState :: R.State NT.CacheState cacheState :: T.Box NT.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: NodeID , corpusId :: NodeID
, frontends :: Frontends , frontends :: Frontends
......
...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude import Gargantext.Prelude
...@@ -42,8 +43,7 @@ stateParams {pageSize, page, orderBy, searchType} = {offset, limit, orderBy, sea ...@@ -42,8 +43,7 @@ stateParams {pageSize, page, orderBy, searchType} = {offset, limit, orderBy, sea
offset = limit * (page - 1) offset = limit * (page - 1)
type TableHeaderLayoutProps = ( type TableHeaderLayoutProps = (
afterCacheStateChange :: NT.CacheState -> Effect Unit cacheState :: T.Box NT.CacheState
, cacheState :: R.State NT.CacheState
, date :: String , date :: String
, desc :: String , desc :: String
, key :: String , key :: String
...@@ -56,58 +56,57 @@ initialParams :: Params ...@@ -56,58 +56,57 @@ initialParams :: Params
initialParams = stateParams {page: 1, pageSize: PS10, orderBy: Nothing, searchType: SearchDoc} initialParams = stateParams {page: 1, pageSize: PS10, orderBy: Nothing, searchType: SearchDoc}
-- TODO: Not sure this is the right place for this -- TODO: Not sure this is the right place for this
tableHeaderLayout :: Record TableHeaderLayoutProps -> R.Element tableHeaderLayout :: R2.Component TableHeaderLayoutProps
tableHeaderLayout props = R.createElement tableHeaderLayoutCpt props [] tableHeaderLayout = R.createElement tableHeaderLayoutCpt
tableHeaderLayoutCpt :: R.Component TableHeaderLayoutProps tableHeaderLayoutCpt :: R.Component TableHeaderLayoutProps
tableHeaderLayoutCpt = here.component "tableHeaderLayout" cpt tableHeaderLayoutCpt = here.component "tableHeaderLayout" cpt
where where
cpt { afterCacheStateChange, cacheState, date, desc, query, title, user } _ = cpt { cacheState, date, desc, query, title, user } _ = do
cacheState' <- T.useLive T.unequal cacheState
pure $ R.fragment pure $ R.fragment
[ R2.row [ R2.row
[ H.div {className: "col-md-3"} [ H.h3 {} [H.text title] ] [ H.div {className: "col-md-3"} [ H.h3 {} [H.text title] ]
, H.div {className: "col-md-9"} , H.div {className: "col-md-9"}
[ H.hr {style: {height: "2px", backgroundColor: "black"}} ] [ H.hr {style: {height: "2px", backgroundColor: "black"}} ]
]
, R2.row
[ H.div {className: "col-md-8 content"}
[ H.p {}
[ H.span {className: "fa fa-globe"} []
, H.text $ " " <> desc
]
, H.p {}
[ H.span {className: "fa fa-search-plus"} []
, H.text $ " " <> query
]
, H.p { className: "cache-toggle"
, on: { click: cacheClick cacheState afterCacheStateChange } }
[ H.span { className: "fa " <> (cacheToggle cacheState) } []
, H.text $ cacheText cacheState
]
] ]
, H.div {className: "col-md-4 content"} , R2.row
[ H.p {} [ H.div {className: "col-md-8 content"}
[ H.span {className: "fa fa-calendar"} [] [ H.p {}
, H.text $ " " <> date [ H.span {className: "fa fa-globe"} []
] , H.text $ " " <> desc
, H.p {} ]
[ H.span {className: "fa fa-user"} [] , H.p {}
, H.text $ " " <> user [ H.span {className: "fa fa-search-plus"} []
, H.text $ " " <> query
]
, H.p { className: "cache-toggle"
, on: { click: cacheClick cacheState } }
[ H.span { className: "fa " <> (cacheToggle cacheState') } []
, H.text $ cacheText cacheState'
]
]
, H.div {className: "col-md-4 content"}
[ H.p {}
[ H.span {className: "fa fa-calendar"} []
, H.text $ " " <> date
]
, H.p {}
[ H.span {className: "fa fa-user"} []
, H.text $ " " <> user
]
]
] ]
] ]
]
]
cacheToggle (NT.CacheOn /\ _) = "fa-toggle-on" cacheToggle NT.CacheOn = "fa-toggle-on"
cacheToggle (NT.CacheOff /\ _) = "fa-toggle-off" cacheToggle NT.CacheOff = "fa-toggle-off"
cacheText (NT.CacheOn /\ _) = "Cache On" cacheText NT.CacheOn = "Cache On"
cacheText (NT.CacheOff /\ _) = "Cache Off" cacheText NT.CacheOff = "Cache Off"
cacheClick (cacheState /\ setCacheState) after _ = do cacheClick cacheState _ = do
setCacheState $ const newCacheState T.modify cacheStateToggle cacheState
after newCacheState
where
newCacheState = cacheStateToggle cacheState
cacheStateToggle NT.CacheOn = NT.CacheOff cacheStateToggle NT.CacheOn = NT.CacheOff
cacheStateToggle NT.CacheOff = NT.CacheOn cacheStateToggle NT.CacheOff = NT.CacheOn
......
module Gargantext.Utils.Reload where
import Gargantext.Prelude
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Reactix as R
import Toestand as T
type Reload = Int
type ReloadS = R.State Reload
type ReloadSRef = R.Ref
new :: R.Hooks ReloadS
new = R.useState' 0
bump :: ReloadS -> Effect Unit
bump (_ /\ setReload) = setReload (_ + 1)
bumpBox :: T.Box Reload -> Effect Unit
bumpBox c = T.modify_ (_ + 1) c
value :: ReloadS -> Reload
value (val /\ _) = val
-- a ReloadS ref that can be initialized later
data ReloadWithInitialize = Initialize | Ready ReloadS
type ReloadWithInitializeRef = R.Ref ReloadWithInitialize
newI :: R.Hooks ReloadWithInitializeRef
newI = R.useRef Initialize
newIInitialized :: ReloadS -> R.Hooks ReloadWithInitializeRef
newIInitialized reload = R.useRef $ Ready reload
initializeI :: ReloadWithInitializeRef -> ReloadS -> Effect Unit
initializeI ref reloadS = case R.readRef ref of
Initialize -> R.setRef ref $ Ready reloadS
Ready _ -> pure unit
bumpI :: ReloadWithInitializeRef -> Effect Unit
bumpI ref = case R.readRef ref of
Initialize -> pure unit
Ready reload -> bump reload
module Gargantext.Utils.Toestand module Gargantext.Utils.Toestand
( class Reloadable, reload, Reload, newReload, InitReload(..), ready, useMemberBox ) ( class Reloadable, reload, Reload, ReloadS, newReload, InitReload(..), ready, useMemberBox )
where where
import Prelude (class Ord, Unit, bind, pure, unit, (+)) import Prelude (class Ord, Unit, bind, pure, unit, (+))
...@@ -11,6 +11,7 @@ import Toestand as T ...@@ -11,6 +11,7 @@ import Toestand as T
-- | Reload is a simple counter that can be used to force an update. -- | Reload is a simple counter that can be used to force an update.
type Reload = Int type Reload = Int
type ReloadS = T.Box Reload
class Reloadable t where class Reloadable t where
reload :: t -> Effect Unit reload :: t -> Effect Unit
......
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