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

[ngrams] asyncTasksRef

parent bcc6aaa6
......@@ -52,20 +52,20 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
sessions <- useSessions
route <- useHashRouter router Home
asyncTasksRef <- R.useRef Nothing
showLogin <- R.useState' false
backend <- R.useState' Nothing
treeReload <- R.useState' 0
asyncTasks <- GAT.useTasks treeReload
showCorpus <- R.useState' false
handed <- R.useState' GT.RightHanded
let backends = fromFoldable defaultBackends
let ff f session = R.fragment [ f session, footer { session } ]
let forested child = forestLayout { asyncTasks
let forested child = forestLayout { asyncTasksRef
, child
, frontends
, handed
......@@ -93,12 +93,13 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
Annuaire sid nodeId -> withSession sid $ \session -> forested $ annuaireLayout { frontends, nodeId, session }
ContactPage sid aId nodeId -> withSession sid $ \session -> forested $ annuaireUserLayout {
annuaireId: aId
, asyncTasks: snd asyncTasks, frontends
, asyncTasksRef
, frontends
, nodeId
, session
}
Corpus sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested $ documentLayout { nodeId, listId, session, corpusId: Just corpusId }
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested $ documentLayout { corpusId: Just corpusId, nodeId, listId, session }
Dashboard sid nodeId -> withSession sid $ \session -> forested $ dashboardLayout { nodeId, session }
Document sid listId nodeId ->
withSession sid $
......@@ -109,7 +110,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
FolderShared sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
Home -> forested $ homeLayout { backend, lang:LL_EN, publicBackend, sessions, visible: showLogin }
Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout {
asyncTasks: snd asyncTasks
asyncTasksRef
, nodeId
, session
, sessionUpdate
......@@ -119,7 +120,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
withSession sid $
\session ->
simpleLayout handed $
explorerLayout { asyncTasks
explorerLayout { asyncTasksRef
, backend
, frontends
, graphId
......@@ -137,22 +138,22 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
Team sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { frontends, nodeId, session, sessionUpdate }
UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout {
asyncTasks: snd asyncTasks
asyncTasksRef
, frontends
, nodeId
, session
}
type ForestLayoutProps =
( asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend)
, child :: R.Element
, frontends :: Frontends
, handed :: R.State GT.Handed
, reload :: R.State Int
, route :: AppRoute
, sessions :: Sessions
, showLogin :: R.Setter Boolean
type ForestLayoutProps = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, child :: R.Element
, frontends :: Frontends
, handed :: R.State GT.Handed
, reload :: R.State Int
, route :: AppRoute
, sessions :: Sessions
, showLogin :: R.Setter Boolean
)
forestLayout :: Record ForestLayoutProps -> R.Element
......@@ -170,7 +171,7 @@ forestLayoutMain props = R.createElement forestLayoutMainCpt props []
forestLayoutMainCpt :: R.Component ForestLayoutProps
forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" cpt
where
cpt { asyncTasks, child, frontends, handed, reload, route, sessions, showLogin, backend} _ = do
cpt { asyncTasksRef, child, frontends, handed, reload, route, sessions, showLogin, backend} _ = do
let ordering =
case fst handed of
GT.LeftHanded -> reverse
......@@ -178,7 +179,7 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c
pure $ R2.row $ ordering [
H.div { className: "col-md-2", style: { paddingTop: "60px" } }
[ forest { asyncTasks, backend, frontends, handed: fst handed, reload, route, sessions, showLogin } ]
[ forest { asyncTasksRef, backend, frontends, handed: fst handed, reload, route, sessions, showLogin } ]
, mainPage child
]
......
......@@ -21,15 +21,15 @@ import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Forest"
type Props =
( asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend)
, frontends :: Frontends
, handed :: Handed
, reload :: R.State Int
, route :: AppRoute
, sessions :: Sessions
, showLogin :: R.Setter Boolean
type Props = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, frontends :: Frontends
, handed :: Handed
, reload :: R.State Int
, route :: AppRoute
, sessions :: Sessions
, showLogin :: R.Setter Boolean
)
forest :: Record Props -> R.Element
......@@ -37,12 +37,17 @@ forest props = R.createElement forestCpt props []
forestCpt :: R.Component Props
forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where
cpt { asyncTasks, frontends, handed, reload: extReload, route, sessions, showLogin, backend} _ = do
cpt { asyncTasksRef, frontends, handed, reload: extReload, route, sessions, showLogin, backend} _ = do
-- NOTE: this is a hack to reload the tree view on demand
asyncTasks <- GAT.useTasks extReload
reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
R2.useCache
( frontends
R.useEffect' $ do
R.setRef asyncTasksRef $ Just asyncTasks
R2.useCache (
frontends
/\ route
/\ sessions
/\ fst openNodes
......
......@@ -42,7 +42,7 @@ thisModule :: String
thisModule = "Gargantext.Components.GraphExplorer"
type LayoutProps = (
asyncTasks :: GAT.Reductor
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, frontends :: Frontends
, graphId :: GET.GraphId
......@@ -92,7 +92,7 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props
explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
where
cpt props@{ asyncTasks
cpt props@{ asyncTasksRef
, frontends
, graph
, graphId
......@@ -157,7 +157,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
[ inner handed
[ rowControls [ Controls.controls controls ]
, R2.row $ mainLayout handed $
tree { asyncTasks
tree { asyncTasksRef
, backend
, frontends
, handed
......@@ -212,9 +212,9 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
tree :: Record TreeProps -> R.Element
tree { show: false } = RH.div { id: "tree" } []
tree { asyncTasks, backend, frontends, handed, mCurrentRoute: route, reload, sessions, showLogin } =
tree { asyncTasksRef, backend, frontends, handed, mCurrentRoute: route, reload, sessions, showLogin } =
RH.div {className: "col-md-2 graph-tree"} [
forest { asyncTasks, backend, frontends, handed, reload, route, sessions, showLogin }
forest { asyncTasksRef, backend, frontends, handed, reload, route, sessions, showLogin }
]
mSidebar :: Maybe GET.MetaData
......@@ -226,7 +226,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
type TreeProps =
(
asyncTasks :: GAT.Reductor
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, frontends :: Frontends
, handed :: Types.Handed
......
......@@ -22,7 +22,7 @@ import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log, log2)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
......@@ -280,7 +280,7 @@ tableContainerCpt { dispatch
-- NEXT
type Props = (
afterSync :: Unit -> Aff Unit
, asyncTasks :: GAT.ReductorAction
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, path :: R.State PageParams
, state :: R.State State
, tabNgramType :: CTabNgramType
......@@ -295,7 +295,7 @@ loadedNgramsTableCpt :: R.Component Props
loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" cpt
where
cpt { afterSync
, asyncTasks
, asyncTasksRef
, path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath)
, state: (state@{ ngramsChildren
, ngramsLocalPatch
......@@ -341,7 +341,9 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
task <- postNgramsChartsAsync path'
liftEffect $ do
log2 "[performAction] Synchronize task" task
asyncTasks $ GAT.Insert nodeId task
case R.readRef asyncTasksRef of
Nothing -> log "[performAction] asyncTasksRef is Nothing"
Just asyncTasks -> snd asyncTasks $ GAT.Insert nodeId task
autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then
......@@ -494,15 +496,15 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng
type MainNgramsTableProps = (
afterSync :: Unit -> Aff Unit
, asyncTasks :: GAT.ReductorAction
, cacheState :: R.State NT.CacheState
, defaultListId :: Int
, nodeId :: Int
afterSync :: Unit -> Aff Unit
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NT.CacheState
, defaultListId :: Int
, nodeId :: Int
-- ^ This node can be a corpus or contact.
, session :: Session
, tabNgramType :: CTabNgramType
, tabType :: TabType
, session :: Session
, tabNgramType :: CTabNgramType
, tabType :: TabType
, withAutoUpdate :: Boolean
)
......@@ -513,7 +515,7 @@ mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
where
cpt props@{ afterSync
, asyncTasks
, asyncTasksRef
, cacheState
, defaultListId
, nodeId
......@@ -523,7 +525,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
, withAutoUpdate } _ = do
let path = initialPageParams session nodeId [defaultListId] tabType
let render versioned = mainNgramsTablePaint { afterSync
, asyncTasks
, asyncTasksRef
, path
, tabNgramType
, versioned
......@@ -587,7 +589,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
type MainNgramsTablePaintProps = (
afterSync :: Unit -> Aff Unit
, asyncTasks :: GAT.ReductorAction
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, path :: PageParams
, tabNgramType :: CTabNgramType
, versioned :: VersionedNgramsTable
......@@ -600,13 +602,13 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p []
mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps
mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaint" cpt
where
cpt props@{ afterSync, asyncTasks, path, tabNgramType, versioned, withAutoUpdate } _ = do
cpt props@{ afterSync, asyncTasksRef, path, tabNgramType, versioned, withAutoUpdate } _ = do
pathS <- R.useState' path
state <- R.useState' $ initialState versioned
pure $ loadedNgramsTable {
afterSync
, asyncTasks
, asyncTasksRef
, path: pathS
, state
, tabNgramType
......@@ -616,7 +618,7 @@ mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTable
-- type MainNgramsTablePaintWithStateProps = (
-- afterSync :: Unit -> Aff Unit
-- , asyncTasks :: GAT.Reductor
-- , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
-- , path :: R.State PageParams
-- , tabNgramType :: CTabNgramType
-- , versioned :: VersionedNgramsTable
......@@ -629,12 +631,12 @@ mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTable
-- mainNgramsTablePaintWithStateCpt :: R.Component MainNgramsTablePaintWithStateProps
-- mainNgramsTablePaintWithStateCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaintWithState" cpt
-- where
-- cpt { afterSync, asyncTasks, path, tabNgramType, versioned, withAutoUpdate } _ = do
-- cpt { afterSync, asyncTasksRef, path, tabNgramType, versioned, withAutoUpdate } _ = do
-- state <- R.useState' $ initialState versioned
-- pure $ loadedNgramsTable {
-- afterSync
-- , asyncTasks
-- , asyncTasksRef
-- , path
-- , state
-- , tabNgramType
......
......@@ -145,10 +145,10 @@ infoRender (Tuple title content) =
, H.span {} [H.text content] ]
type LayoutProps = (
asyncTasks :: GAT.ReductorAction
, frontends :: Frontends
, nodeId :: Int
, session :: Session
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, frontends :: Frontends
, nodeId :: Int
, session :: Session
)
type KeyLayoutProps = (
......@@ -162,10 +162,10 @@ userLayout props = R.createElement userLayoutCpt props []
userLayoutCpt :: R.Component LayoutProps
userLayoutCpt = R.hooksComponentWithModule thisModule "userLayout" cpt
where
cpt { asyncTasks, frontends, nodeId, session } _ = do
cpt { asyncTasksRef, frontends, nodeId, session } _ = do
let sid = sessionId session
pure $ userLayoutWithKey { asyncTasks, frontends, key: show sid <> "-" <> show nodeId, nodeId, session }
pure $ userLayoutWithKey { asyncTasksRef, frontends, key: show sid <> "-" <> show nodeId, nodeId, session }
userLayoutWithKey :: Record KeyLayoutProps -> R.Element
userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props []
......@@ -173,7 +173,7 @@ userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props []
userLayoutWithKeyCpt :: R.Component KeyLayoutProps
userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey" cpt
where
cpt { asyncTasks, frontends, nodeId, session } _ = do
cpt { asyncTasksRef, frontends, nodeId, session } _ = do
reload <- R.useState' 0
cacheState <- R.useState' NT.CacheOn
......@@ -182,7 +182,7 @@ userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey"
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" } [
display (fromMaybe "no name" name) (contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs { asyncTasks, cacheState, contactData, frontends, nodeId, session }
, Tabs.tabs { asyncTasksRef, cacheState, contactData, frontends, nodeId, session }
]
where
onUpdateHyperdata :: R.State Int -> HyperdataUser -> Effect Unit
......@@ -224,14 +224,14 @@ annuaireUserLayout props = R.createElement annuaireUserLayoutCpt props []
annuaireUserLayoutCpt :: R.Component AnnuaireLayoutProps
annuaireUserLayoutCpt = R.hooksComponentWithModule thisModule "annuaireUserLayout" cpt
where
cpt { annuaireId, asyncTasks, frontends, nodeId, session } _ = do
cpt { annuaireId, asyncTasksRef, 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 { asyncTasks, cacheState, contactData, frontends, nodeId, session } ]
, Tabs.tabs { asyncTasksRef, cacheState, contactData, frontends, nodeId, session } ]
where
onUpdateHyperdata :: HyperdataUser -> Effect Unit
......
......@@ -44,12 +44,12 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors
type TabsProps = (
asyncTasks :: GAT.ReductorAction
, cacheState :: R.State NTypes.CacheState
, contactData :: ContactData
, frontends :: Frontends
, nodeId :: Int
, session :: Session
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState
, contactData :: ContactData
, frontends :: Frontends
, nodeId :: Int
, session :: Session
)
tabs :: Record TabsProps -> R.Element
......@@ -58,7 +58,7 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps
tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
where
cpt { asyncTasks, cacheState, contactData: {defaultListId}, frontends, nodeId, session} _ = do
cpt { asyncTasksRef, cacheState, contactData: {defaultListId}, frontends, nodeId, session} _ = do
active <- R.useState' 0
pure $
Tab.tabs { selected: fst active, tabs: tabs' }
......@@ -71,9 +71,9 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
, "Trash" /\ docs -- TODO pass-in trash mode
]
where
patentsView = { asyncTasks, cacheState, defaultListId, mode: Patents, nodeId, session }
booksView = { asyncTasks, cacheState, defaultListId, mode: Books, nodeId, session }
commView = { asyncTasks, cacheState, defaultListId, mode: Communication, nodeId, session }
patentsView = { asyncTasksRef, cacheState, defaultListId, mode: Patents, nodeId, session }
booksView = { asyncTasksRef, cacheState, defaultListId, mode: Books, nodeId, session }
commView = { asyncTasksRef, cacheState, defaultListId, mode: Communication, nodeId, session }
chart = mempty
totalRecords = 4736 -- TODO
docs = DT.docViewLayout
......@@ -91,7 +91,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
type NgramsViewTabsProps = (
asyncTasks :: GAT.ReductorAction
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState
, defaultListId :: Int
, mode :: Mode
......@@ -100,10 +100,10 @@ type NgramsViewTabsProps = (
)
ngramsView :: Record NgramsViewTabsProps -> R.Element
ngramsView { asyncTasks, cacheState, defaultListId, mode, nodeId, session } =
ngramsView { asyncTasksRef, cacheState, defaultListId, mode, nodeId, session } =
NT.mainNgramsTable {
afterSync: \_ -> pure unit
, asyncTasks
, asyncTasksRef
, cacheState
, defaultListId
, nodeId
......
module Gargantext.Components.Nodes.Lists where
import Data.Maybe (Maybe(..))
import Data.Tuple (fst)
import Effect (Effect)
import Effect.Aff (launchAff_)
......@@ -25,7 +26,7 @@ thisModule = "Gargantext.Components.Nodes.Lists"
------------------------------------------------------------------------
type Props = (
asyncTasks :: GAT.ReductorAction
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, nodeId :: Int
, session :: Session
, sessionUpdate :: Session -> Effect Unit
......@@ -53,7 +54,7 @@ listsLayoutWithKey props = R.createElement listsLayoutWithKeyCpt props []
listsLayoutWithKeyCpt :: R.Component KeyProps
listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKey" cpt
where
cpt { asyncTasks, nodeId, session, sessionUpdate } _ = do
cpt { asyncTasksRef, nodeId, session, sessionUpdate } _ = do
let path = { nodeId, session }
cacheState <- R.useState' $ getCacheState NT.CacheOn session nodeId
......@@ -74,7 +75,7 @@ listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKe
, title: "Corpus " <> name
, user: authors }
, Tabs.tabs {
asyncTasks
asyncTasksRef
, cacheState
, corpusData
, corpusId
......
......@@ -26,11 +26,11 @@ thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists.Tabs"
type Props = (
asyncTasks :: GAT.ReductorAction
, cacheState :: R.State NTypes.CacheState
, corpusData :: CorpusData
, corpusId :: Int
, session :: Session
asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState
, corpusData :: CorpusData
, corpusId :: Int
, session :: Session
)
type PropsWithKey = (
......@@ -44,7 +44,7 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component PropsWithKey
tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
where
cpt { asyncTasks, cacheState, corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do
cpt { asyncTasksRef, cacheState, corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do
(selected /\ setSelected) <- R.useState' 0
pure $ Tab.tabs { selected, tabs: tabs' }
......@@ -53,7 +53,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
, "Institutes" /\ view Institutes
, "Sources" /\ view Sources
, "Terms" /\ view Terms ]
view mode = ngramsView { asyncTasks, cacheState, corpusData, corpusId, mode, session }
view mode = ngramsView { asyncTasksRef, cacheState, corpusData, corpusId, mode, session }
type NgramsViewProps = ( mode :: Mode | Props )
......@@ -63,7 +63,7 @@ ngramsView props = R.createElement ngramsViewCpt props []
ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
where
cpt { asyncTasks
cpt { asyncTasksRef
, cacheState
, corpusData: { defaultListId }
, corpusId
......@@ -76,7 +76,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
pure $ R.fragment
( charts tabNgramType chartType chartsReload
<> [ NT.mainNgramsTable { afterSync: afterSync chartsReload
, asyncTasks
, asyncTasksRef
, cacheState
, defaultListId
, nodeId: corpusId
......
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