Commit 361bc8ca authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] more asyncTasks refactoring

parent 48f62a98
...@@ -55,6 +55,7 @@ type ReductorProps = ( ...@@ -55,6 +55,7 @@ type ReductorProps = (
type Reductor = R2.Reductor (Record ReductorProps) Action type Reductor = R2.Reductor (Record ReductorProps) Action
type ReductorAction = Action -> Effect Unit type ReductorAction = Action -> Effect Unit
type OnFinish = Effect Unit
useTasks :: R.State Int -> R.Hooks Reductor useTasks :: R.State Int -> R.Hooks Reductor
useTasks reload = R2.useReductor act initializer unit useTasks reload = R2.useReductor act initializer unit
...@@ -67,6 +68,7 @@ useTasks reload = R2.useReductor act initializer unit ...@@ -67,6 +68,7 @@ useTasks reload = R2.useReductor act initializer unit
data Action = data Action =
Insert NodeId GT.AsyncTaskWithType Insert NodeId GT.AsyncTaskWithType
| Finish NodeId GT.AsyncTaskWithType OnFinish
| Remove NodeId GT.AsyncTaskWithType | Remove NodeId GT.AsyncTaskWithType
action :: Record ReductorProps -> Action -> Effect (Record ReductorProps) action :: Record ReductorProps -> Action -> Effect (Record ReductorProps)
...@@ -74,6 +76,10 @@ action { reload, storage } (Insert nodeId t) = do ...@@ -74,6 +76,10 @@ action { reload, storage } (Insert nodeId t) = do
_ <- snd reload $ (_ + 1) _ <- snd reload $ (_ + 1)
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 { reload, storage: newStorage } pure { reload, storage: newStorage }
action p@{ reload, storage } (Finish nodeId t onFinish) = do
ret <- action p (Remove nodeId t)
onFinish
pure ret
action { reload, storage } (Remove nodeId t) = do action { reload, storage } (Remove nodeId t) = do
_ <- snd reload $ (_ + 1) _ <- snd reload $ (_ + 1)
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
......
...@@ -57,7 +57,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -57,7 +57,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
showLogin <- R.useState' false showLogin <- R.useState' false
backend <- R.useState' Nothing backend <- R.useState' Nothing
treeReload <- R.useState' 0 reload <- R.useState' 0
showCorpus <- R.useState' false showCorpus <- R.useState' false
...@@ -69,7 +69,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -69,7 +69,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, child , child
, frontends , frontends
, handed , handed
, reload: treeReload , reload
, route: fst route , route: fst route
, sessions: fst sessions , sessions: fst sessions
, showLogin: snd showLogin , showLogin: snd showLogin
...@@ -93,6 +93,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -93,6 +93,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
Annuaire sid nodeId -> withSession sid $ \session -> forested $ annuaireLayout { frontends, nodeId, session } Annuaire sid nodeId -> withSession sid $ \session -> forested $ annuaireLayout { frontends, nodeId, session }
ContactPage sid aId nodeId -> withSession sid $ \session -> forested $ annuaireUserLayout { ContactPage sid aId nodeId -> withSession sid $ \session -> forested $ annuaireUserLayout {
annuaireId: aId annuaireId: aId
, appReload: reload
, asyncTasksRef , asyncTasksRef
, frontends , frontends
, nodeId , nodeId
...@@ -110,7 +111,8 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -110,7 +111,8 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
FolderShared sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } FolderShared sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
Home -> forested $ homeLayout { backend, lang:LL_EN, publicBackend, sessions, visible: showLogin } Home -> forested $ homeLayout { backend, lang:LL_EN, publicBackend, sessions, visible: showLogin }
Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout { Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout {
asyncTasksRef appReload: reload
, asyncTasksRef
, nodeId , nodeId
, session , session
, sessionUpdate , sessionUpdate
...@@ -129,7 +131,6 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -129,7 +131,6 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, session , session
, sessions: (fst sessions) , sessions: (fst sessions)
, showLogin , showLogin
--, treeReload
} }
RouteFile sid nodeId -> withSession sid $ \session -> forested $ fileLayout { nodeId, session } RouteFile sid nodeId -> withSession sid $ \session -> forested $ fileLayout { nodeId, session }
RouteFrameCalc sid nodeId -> withSession sid $ \session -> forested $ frameLayout { nodeId, session, nodeType: GT.NodeFrameCalc } RouteFrameCalc sid nodeId -> withSession sid $ \session -> forested $ frameLayout { nodeId, session, nodeType: GT.NodeFrameCalc }
...@@ -138,7 +139,8 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -138,7 +139,8 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
Team sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } Team sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session }
Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { frontends, nodeId, session, sessionUpdate } Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { frontends, nodeId, session, sessionUpdate }
UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout { UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout {
asyncTasksRef appReload: reload
, asyncTasksRef
, frontends , frontends
, nodeId , nodeId
, session , session
......
...@@ -39,8 +39,8 @@ forestCpt :: R.Component Props ...@@ -39,8 +39,8 @@ forestCpt :: R.Component Props
forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where
cpt { asyncTasksRef, 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 -- NOTE: this is a hack to reload the tree view on demand
asyncTasks <- GAT.useTasks extReload
reload <- R.useState' (0 :: Reload) reload <- R.useState' (0 :: Reload)
asyncTasks <- GAT.useTasks reload
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes) openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
R.useEffect' $ do R.useEffect' $ do
......
...@@ -176,10 +176,6 @@ toHtmlCpt = R.hooksComponentWithModule thisModule "nodeView" cpt ...@@ -176,10 +176,6 @@ toHtmlCpt = R.hooksComponentWithModule thisModule "nodeView" cpt
, openNodes , openNodes
, reload: reload@(_ /\ setReload) , reload: reload@(_ /\ setReload)
, session , session
-- , tasks: tasks@{ onTaskAdd
-- , onTaskFinish
-- , tasks: tasks'
-- }
, tree: tree@(NTree (LNode { id , tree: tree@(NTree (LNode { id
, name , name
, nodeType , nodeType
...@@ -199,7 +195,8 @@ toHtmlCpt = R.hooksComponentWithModule thisModule "nodeView" cpt ...@@ -199,7 +195,8 @@ toHtmlCpt = R.hooksComponentWithModule thisModule "nodeView" cpt
let withId (NTree (LNode {id: id'}) _) = id' let withId (NTree (LNode {id: id'}) _) = id'
pure $ H.li { className: if A.null ary then "no-children" else "with-children" } $ pure $ H.li { className: if A.null ary then "no-children" else "with-children" } $
[ nodeMainSpan { asyncTasks [ nodeMainSpan { appReload: reload
, asyncTasks
, dispatch: pAction , dispatch: pAction
, folderOpen , folderOpen
, frontends , frontends
...@@ -288,7 +285,6 @@ performAction (DoSearch task) { asyncTasks: (_ /\ dispatch) ...@@ -288,7 +285,6 @@ performAction (DoSearch task) { asyncTasks: (_ /\ dispatch)
------- -------
performAction (UpdateNode params) { asyncTasks: (_ /\ dispatch) performAction (UpdateNode params) { asyncTasks: (_ /\ dispatch)
, session , session
-- , tasks: {onTaskAdd}
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.Forest.Tree.Node where ...@@ -3,6 +3,7 @@ module Gargantext.Components.Forest.Tree.Node where
import Data.Array (reverse) import Data.Array (reverse)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (null) import Data.Nullable (null)
import Data.Tuple (snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff) import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -40,8 +41,9 @@ thisModule = "Gargantext.Components.Forest.Tree.Node" ...@@ -40,8 +41,9 @@ thisModule = "Gargantext.Components.Forest.Tree.Node"
-- Main Node -- Main Node
type NodeMainSpanProps = type NodeMainSpanProps = (
( asyncTasks :: GAT.Reductor appReload :: R.State Int
, asyncTasks :: GAT.Reductor
, folderOpen :: R.State Boolean , folderOpen :: R.State Boolean
, frontends :: Frontends , frontends :: Frontends
, id :: ID , id :: ID
...@@ -61,7 +63,8 @@ nodeMainSpan p = R.createElement nodeMainSpanCpt p [] ...@@ -61,7 +63,8 @@ nodeMainSpan p = R.createElement nodeMainSpanCpt p []
nodeMainSpanCpt :: R.Component NodeMainSpanProps nodeMainSpanCpt :: R.Component NodeMainSpanProps
nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt
where where
cpt props@{ asyncTasks: (asyncTasks /\ dispatchAsyncTasks) cpt props@{ appReload
, asyncTasks: (asyncTasks /\ dispatchAsyncTasks)
, dispatch , dispatch
, folderOpen , folderOpen
, frontends , frontends
...@@ -104,7 +107,7 @@ nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt ...@@ -104,7 +107,7 @@ nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t , H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, barType: Pie , barType: Pie
, nodeId: id , nodeId: id
, onFinish: const $ dispatchAsyncTasks $ GAT.Remove id t , onFinish: onTaskFinish id t
, session , session
} }
) $ GAT.getTasks asyncTasks id ) $ GAT.getTasks asyncTasks id
...@@ -134,6 +137,9 @@ nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt ...@@ -134,6 +137,9 @@ nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt
] ]
where where
onTaskFinish id t _ = do
dispatchAsyncTasks $ GAT.Finish id t (snd appReload $ (_ + 1))
SettingsBox {show: showBox} = settingsBox nodeType SettingsBox {show: showBox} = settingsBox nodeType
onPopoverClose popoverRef _ = Popover.setOpen popoverRef false onPopoverClose popoverRef _ = Popover.setOpen popoverRef false
......
...@@ -24,6 +24,7 @@ import Gargantext.Utils (toggleSet) ...@@ -24,6 +24,7 @@ import Gargantext.Utils (toggleSet)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.ReactTooltip as ReactTooltip import Gargantext.Utils.ReactTooltip as ReactTooltip
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node.Tools" thisModule = "Gargantext.Components.Forest.Tree.Node.Tools"
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -246,7 +247,9 @@ checkboxes :: forall a ...@@ -246,7 +247,9 @@ checkboxes :: forall a
-> R.State (Set a) -> R.State (Set a)
-> R.Element -> R.Element
checkboxes xs (val /\ set) = checkboxes xs (val /\ set) =
H.fieldset {} $ map (\a -> H.div {} [ H.input { type: "checkbox" H.fieldset {} $ map (
\a -> H.div {} [
H.input { type: "checkbox"
, checked: Set.member a val , checked: Set.member a val
, on: { click: \_ -> set , on: { click: \_ -> set
$ const $ const
......
module Gargantext.Components.Forest.Tree.Node.Tools.Task
where
import Data.Array as A
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Reactix as R
import Gargantext.AsyncTasks as GAT
import Gargantext.Prelude (Unit, discard, identity, ($), (+))
import Gargantext.Types (Reload)
import Gargantext.Types as GT
type Tasks =
( onTaskAdd :: GT.AsyncTaskWithType -> Effect Unit
, onTaskFinish :: GT.AsyncTaskWithType -> Effect Unit
, tasks :: Array GT.AsyncTaskWithType
)
tasksStruct :: Int
-> GAT.Reductor
-> R.State Reload
-> Record Tasks
tasksStruct id ({ storage } /\ dispatch) (_ /\ setReload) =
{ onTaskAdd, onTaskFinish, tasks }
where
tasks = maybe [] identity $ Map.lookup id storage
onTaskAdd t = dispatch $ GAT.Insert id t
onTaskFinish t = dispatch $ GAT.Remove id t
...@@ -10,6 +10,7 @@ import Reactix as R ...@@ -10,6 +10,7 @@ import Reactix as R
import Gargantext.Components.LoadingSpinner (loadingSpinner) import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Loader" thisModule = "Gargantext.Components.Loader"
type Props path loaded = type Props path loaded =
......
...@@ -31,6 +31,8 @@ import Reactix.DOM.HTML as H ...@@ -31,6 +31,8 @@ import Reactix.DOM.HTML as H
import Record as Record import Record as Record
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.AutoUpdate (autoUpdateElt) import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
...@@ -39,7 +41,6 @@ import Gargantext.Components.NgramsTable.Core ...@@ -39,7 +41,6 @@ import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI) import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
import Gargantext.Components.Nodes.Lists.Types as NT import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), read, otherwise)
import Gargantext.Routes (SessionRoute(..)) as R import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes) import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
...@@ -279,7 +280,8 @@ tableContainerCpt { dispatch ...@@ -279,7 +280,8 @@ tableContainerCpt { dispatch
-- NEXT -- NEXT
type Props = ( type Props = (
afterSync :: Unit -> Aff Unit appReload :: R.State Int
, afterSync :: Unit -> Aff Unit
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor) , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, path :: R.State PageParams , path :: R.State PageParams
, state :: R.State State , state :: R.State State
...@@ -295,6 +297,7 @@ loadedNgramsTableCpt :: R.Component Props ...@@ -295,6 +297,7 @@ loadedNgramsTableCpt :: R.Component Props
loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" cpt loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" cpt
where where
cpt { afterSync cpt { afterSync
, appReload
, asyncTasksRef , asyncTasksRef
, path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath) , path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath)
, state: (state@{ ngramsChildren , state: (state@{ ngramsChildren
...@@ -306,10 +309,12 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" ...@@ -306,10 +309,12 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, versioned: Versioned { data: initTable } , versioned: Versioned { data: initTable }
, withAutoUpdate } _ = do , withAutoUpdate } _ = do
let syncResetBtns = [syncResetButtons { afterSync: chartsAfterSync let syncResetBtns = [
syncResetButtons { afterSync: chartsAfterSync
, ngramsLocalPatch , ngramsLocalPatch
, performAction: performAction <<< CoreAction , performAction: performAction <<< CoreAction
}] }
]
pure $ R.fragment $ pure $ R.fragment $
autoUpdate <> syncResetBtns <> [ autoUpdate <> syncResetBtns <> [
...@@ -343,7 +348,9 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" ...@@ -343,7 +348,9 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
log2 "[performAction] Synchronize task" task log2 "[performAction] Synchronize task" task
case R.readRef asyncTasksRef of case R.readRef asyncTasksRef of
Nothing -> log "[performAction] asyncTasksRef is Nothing" Nothing -> log "[performAction] asyncTasksRef is Nothing"
Just asyncTasks -> snd asyncTasks $ GAT.Insert nodeId task Just asyncTasks -> do
snd asyncTasks $ GAT.Insert nodeId task
snd appReload $ (_ + 1)
autoUpdate :: Array R.Element autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then autoUpdate = if withAutoUpdate then
...@@ -497,6 +504,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng ...@@ -497,6 +504,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng
type MainNgramsTableProps = ( type MainNgramsTableProps = (
afterSync :: Unit -> Aff Unit afterSync :: Unit -> Aff Unit
, appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor) , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NT.CacheState , cacheState :: R.State NT.CacheState
, defaultListId :: Int , defaultListId :: Int
...@@ -515,6 +523,7 @@ mainNgramsTableCpt :: R.Component MainNgramsTableProps ...@@ -515,6 +523,7 @@ mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
where where
cpt props@{ afterSync cpt props@{ afterSync
, appReload
, asyncTasksRef , asyncTasksRef
, cacheState , cacheState
, defaultListId , defaultListId
...@@ -525,6 +534,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -525,6 +534,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
, withAutoUpdate } _ = do , withAutoUpdate } _ = do
let path = initialPageParams session nodeId [defaultListId] tabType let path = initialPageParams session nodeId [defaultListId] tabType
let render versioned = mainNgramsTablePaint { afterSync let render versioned = mainNgramsTablePaint { afterSync
, appReload
, asyncTasksRef , asyncTasksRef
, path , path
, tabNgramType , tabNgramType
...@@ -589,6 +599,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -589,6 +599,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
type MainNgramsTablePaintProps = ( type MainNgramsTablePaintProps = (
afterSync :: Unit -> Aff Unit afterSync :: Unit -> Aff Unit
, appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor) , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, path :: PageParams , path :: PageParams
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
...@@ -602,12 +613,13 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p [] ...@@ -602,12 +613,13 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p []
mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps
mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaint" cpt mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaint" cpt
where where
cpt props@{ afterSync, asyncTasksRef, path, tabNgramType, versioned, withAutoUpdate } _ = do cpt props@{ afterSync, appReload, asyncTasksRef, path, tabNgramType, versioned, withAutoUpdate } _ = do
pathS <- R.useState' path pathS <- R.useState' path
state <- R.useState' $ initialState versioned state <- R.useState' $ initialState versioned
pure $ loadedNgramsTable { pure $ loadedNgramsTable {
afterSync afterSync
, appReload
, asyncTasksRef , asyncTasksRef
, path: pathS , path: pathS
, state , state
......
...@@ -932,15 +932,10 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches } ...@@ -932,15 +932,10 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsVersion , ngramsVersion
} /\ setState) callback = do } /\ setState) callback = do
when (isEmptyNgramsTablePatch ngramsStagePatch) $ do when (isEmptyNgramsTablePatch ngramsStagePatch) $ do
-- setState $ \s ->
-- s { ngramsLocalPatch = fromNgramsPatches mempty
-- , ngramsStagePatch = ngramsLocalPatch
-- }
let pt = Versioned { data: ngramsPatches, version: ngramsVersion } let pt = Versioned { data: ngramsPatches, version: ngramsVersion }
launchAff_ $ do launchAff_ $ do
Versioned { data: newPatch, version: newVersion } <- putNgramsPatches props pt Versioned { data: newPatch, version: newVersion } <- putNgramsPatches props pt
callback unit callback unit
-- task <- postNgramsChartsAsync props
liftEffect $ do liftEffect $ do
log2 "[syncPatches] setting state, newVersion" newVersion log2 "[syncPatches] setting state, newVersion" newVersion
setState $ \s -> setState $ \s ->
...@@ -1090,20 +1085,24 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c ...@@ -1090,20 +1085,24 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c
let let
hasChanges = ngramsLocalPatch /= mempty hasChanges = ngramsLocalPatch /= mempty
hasChangesClass = if hasChanges then "" else " disabled"
newAfterSync x = do resetClick _ = do
afterSync x performAction ResetPatches
liftEffect $ setSynchronizing $ const false
synchronizeClick _ = delay unit $ \_ -> do synchronizeClick _ = delay unit $ \_ -> do
setSynchronizing $ const true setSynchronizing $ const true
performAction $ Synchronize { afterSync: newAfterSync } performAction $ Synchronize { afterSync: newAfterSync }
newAfterSync x = do
afterSync x
liftEffect $ setSynchronizing $ const false
pure $ H.div {} [ pure $ H.div {} [
H.button { className: "btn btn-danger " <> if hasChanges then "" else " disabled" H.button { className: "btn btn-danger " <> hasChangesClass
, on: { click: \_ -> performAction ResetPatches } , on: { click: resetClick }
} [ H.text "Reset" ] } [ H.text "Reset" ]
, H.button { className: "btn btn-primary " <> (if s || (not hasChanges) then "disabled" else "") , H.button { className: "btn btn-primary " <> hasChangesClass
, on: { click: synchronizeClick } , on: { click: synchronizeClick }
} [ H.text "Sync" ] } [ H.text "Sync" ]
] ]
...@@ -145,7 +145,8 @@ infoRender (Tuple title content) = ...@@ -145,7 +145,8 @@ infoRender (Tuple title content) =
, H.span {} [H.text content] ] , H.span {} [H.text content] ]
type LayoutProps = ( type LayoutProps = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor) appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, frontends :: Frontends , frontends :: Frontends
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
...@@ -162,10 +163,17 @@ userLayout props = R.createElement userLayoutCpt props [] ...@@ -162,10 +163,17 @@ userLayout props = R.createElement userLayoutCpt props []
userLayoutCpt :: R.Component LayoutProps userLayoutCpt :: R.Component LayoutProps
userLayoutCpt = R.hooksComponentWithModule thisModule "userLayout" cpt userLayoutCpt = R.hooksComponentWithModule thisModule "userLayout" cpt
where where
cpt { asyncTasksRef, frontends, nodeId, session } _ = do cpt { appReload, asyncTasksRef, frontends, nodeId, session } _ = do
let sid = sessionId session let sid = sessionId session
pure $ userLayoutWithKey { asyncTasksRef, frontends, key: show sid <> "-" <> show nodeId, nodeId, session } pure $ userLayoutWithKey {
appReload
, asyncTasksRef
, frontends
, key: show sid <> "-" <> show nodeId
, nodeId
, session
}
userLayoutWithKey :: Record KeyLayoutProps -> R.Element userLayoutWithKey :: Record KeyLayoutProps -> R.Element
userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props [] userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props []
...@@ -173,7 +181,7 @@ userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props [] ...@@ -173,7 +181,7 @@ userLayoutWithKey props = R.createElement userLayoutWithKeyCpt props []
userLayoutWithKeyCpt :: R.Component KeyLayoutProps userLayoutWithKeyCpt :: R.Component KeyLayoutProps
userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey" cpt userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey" cpt
where where
cpt { asyncTasksRef, frontends, nodeId, session } _ = do cpt { appReload, asyncTasksRef, frontends, nodeId, session } _ = do
reload <- R.useState' 0 reload <- R.useState' 0
cacheState <- R.useState' NT.CacheOn cacheState <- R.useState' NT.CacheOn
...@@ -182,7 +190,15 @@ userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey" ...@@ -182,7 +190,15 @@ userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey"
\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 (fromMaybe "no name" name) (contactInfos hyperdata (onUpdateHyperdata reload)) display (fromMaybe "no name" name) (contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs { asyncTasksRef, cacheState, contactData, frontends, nodeId, session } , Tabs.tabs {
appReload
, asyncTasksRef
, cacheState
, contactData
, frontends
, nodeId
, session
}
] ]
where where
onUpdateHyperdata :: R.State Int -> HyperdataUser -> Effect Unit onUpdateHyperdata :: R.State Int -> HyperdataUser -> Effect Unit
...@@ -224,14 +240,23 @@ annuaireUserLayout props = R.createElement annuaireUserLayoutCpt props [] ...@@ -224,14 +240,23 @@ annuaireUserLayout props = R.createElement annuaireUserLayoutCpt props []
annuaireUserLayoutCpt :: R.Component AnnuaireLayoutProps annuaireUserLayoutCpt :: R.Component AnnuaireLayoutProps
annuaireUserLayoutCpt = R.hooksComponentWithModule thisModule "annuaireUserLayout" cpt annuaireUserLayoutCpt = R.hooksComponentWithModule thisModule "annuaireUserLayout" cpt
where where
cpt { annuaireId, asyncTasksRef, frontends, nodeId, session } _ = do cpt { annuaireId, appReload, asyncTasksRef, frontends, nodeId, session } _ = do
cacheState <- R.useState' NT.CacheOn cacheState <- R.useState' NT.CacheOn
useLoader nodeId (getAnnuaireContact session annuaireId) $ useLoader nodeId (getAnnuaireContact session annuaireId) $
\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 (fromMaybe "no name" name) (contactInfos hyperdata onUpdateHyperdata) display (fromMaybe "no name" name) (contactInfos hyperdata onUpdateHyperdata)
, Tabs.tabs { asyncTasksRef, cacheState, contactData, frontends, nodeId, session } ] , Tabs.tabs {
appReload
, asyncTasksRef
, cacheState
, contactData
, frontends
, nodeId
, session
}
]
where where
onUpdateHyperdata :: HyperdataUser -> Effect Unit onUpdateHyperdata :: HyperdataUser -> Effect Unit
......
...@@ -44,7 +44,8 @@ modeTabType' Books = CTabAuthors ...@@ -44,7 +44,8 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors modeTabType' Communication = CTabAuthors
type TabsProps = ( type TabsProps = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor) appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, contactData :: ContactData , contactData :: ContactData
, frontends :: Frontends , frontends :: Frontends
...@@ -58,7 +59,7 @@ tabs props = R.createElement tabsCpt props [] ...@@ -58,7 +59,7 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps tabsCpt :: R.Component TabsProps
tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
where where
cpt { asyncTasksRef, cacheState, contactData: {defaultListId}, frontends, nodeId, session} _ = do cpt { appReload, asyncTasksRef, cacheState, contactData: {defaultListId}, frontends, nodeId, session} _ = do
active <- R.useState' 0 active <- R.useState' 0
pure $ pure $
Tab.tabs { selected: fst active, tabs: tabs' } Tab.tabs { selected: fst active, tabs: tabs' }
...@@ -71,9 +72,9 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -71,9 +72,9 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
, "Trash" /\ docs -- TODO pass-in trash mode , "Trash" /\ docs -- TODO pass-in trash mode
] ]
where where
patentsView = { asyncTasksRef, cacheState, defaultListId, mode: Patents, nodeId, session } patentsView = { appReload, asyncTasksRef, cacheState, defaultListId, mode: Patents, nodeId, session }
booksView = { asyncTasksRef, cacheState, defaultListId, mode: Books, nodeId, session } booksView = { appReload, asyncTasksRef, cacheState, defaultListId, mode: Books, nodeId, session }
commView = { asyncTasksRef, cacheState, defaultListId, mode: Communication, nodeId, session } commView = { appReload, asyncTasksRef, cacheState, defaultListId, mode: Communication, nodeId, session }
chart = mempty chart = mempty
totalRecords = 4736 -- TODO totalRecords = 4736 -- TODO
docs = DT.docViewLayout docs = DT.docViewLayout
...@@ -91,7 +92,8 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -91,7 +92,8 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
type NgramsViewTabsProps = ( type NgramsViewTabsProps = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor) appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, defaultListId :: Int , defaultListId :: Int
, mode :: Mode , mode :: Mode
...@@ -100,9 +102,10 @@ type NgramsViewTabsProps = ( ...@@ -100,9 +102,10 @@ type NgramsViewTabsProps = (
) )
ngramsView :: Record NgramsViewTabsProps -> R.Element ngramsView :: Record NgramsViewTabsProps -> R.Element
ngramsView { asyncTasksRef, cacheState, defaultListId, mode, nodeId, session } = ngramsView { appReload, asyncTasksRef, cacheState, defaultListId, mode, nodeId, session } =
NT.mainNgramsTable { NT.mainNgramsTable {
afterSync: \_ -> pure unit appReload
, afterSync: \_ -> pure unit
, asyncTasksRef , asyncTasksRef
, cacheState , cacheState
, defaultListId , defaultListId
......
...@@ -26,7 +26,8 @@ thisModule = "Gargantext.Components.Nodes.Lists" ...@@ -26,7 +26,8 @@ thisModule = "Gargantext.Components.Nodes.Lists"
------------------------------------------------------------------------ ------------------------------------------------------------------------
type Props = ( type Props = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor) appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
, sessionUpdate :: Session -> Effect Unit , sessionUpdate :: Session -> Effect Unit
...@@ -54,7 +55,7 @@ listsLayoutWithKey props = R.createElement listsLayoutWithKeyCpt props [] ...@@ -54,7 +55,7 @@ listsLayoutWithKey props = R.createElement listsLayoutWithKeyCpt props []
listsLayoutWithKeyCpt :: R.Component KeyProps listsLayoutWithKeyCpt :: R.Component KeyProps
listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKey" cpt listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKey" cpt
where where
cpt { asyncTasksRef, nodeId, session, sessionUpdate } _ = do cpt { appReload, asyncTasksRef, nodeId, session, sessionUpdate } _ = do
let path = { nodeId, session } let path = { nodeId, session }
cacheState <- R.useState' $ getCacheState NT.CacheOn session nodeId cacheState <- R.useState' $ getCacheState NT.CacheOn session nodeId
...@@ -75,7 +76,8 @@ listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKe ...@@ -75,7 +76,8 @@ listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKe
, title: "Corpus " <> name , title: "Corpus " <> name
, user: authors } , user: authors }
, Tabs.tabs { , Tabs.tabs {
asyncTasksRef appReload
, asyncTasksRef
, cacheState , cacheState
, corpusData , corpusData
, corpusId , corpusId
......
...@@ -5,6 +5,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -5,6 +5,7 @@ import Data.Tuple.Nested ((/\))
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 Record as Record
import Gargantext.Prelude import Gargantext.Prelude
...@@ -26,7 +27,8 @@ thisModule :: String ...@@ -26,7 +27,8 @@ thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists.Tabs" thisModule = "Gargantext.Components.Nodes.Lists.Tabs"
type Props = ( type Props = (
asyncTasksRef :: R.Ref (Maybe GAT.Reductor) appReload :: R.State Int
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: Int , corpusId :: Int
...@@ -44,7 +46,7 @@ tabs props = R.createElement tabsCpt props [] ...@@ -44,7 +46,7 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component PropsWithKey tabsCpt :: R.Component PropsWithKey
tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
where where
cpt { asyncTasksRef, cacheState, corpusData: corpusData@{ defaultListId }, corpusId, session } _ = do cpt { appReload, asyncTasksRef, cacheState, corpusData, corpusId, session } _ = do
(selected /\ setSelected) <- R.useState' 0 (selected /\ setSelected) <- R.useState' 0
pure $ Tab.tabs { selected, tabs: tabs' } pure $ Tab.tabs { selected, tabs: tabs' }
...@@ -53,7 +55,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -53,7 +55,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
, "Institutes" /\ view Institutes , "Institutes" /\ view Institutes
, "Sources" /\ view Sources , "Sources" /\ view Sources
, "Terms" /\ view Terms ] , "Terms" /\ view Terms ]
view mode = ngramsView { asyncTasksRef, cacheState, corpusData, corpusId, mode, session } view mode = ngramsView { appReload, asyncTasksRef, cacheState, corpusData, corpusId, mode, session }
type NgramsViewProps = ( mode :: Mode | Props ) type NgramsViewProps = ( mode :: Mode | Props )
...@@ -63,7 +65,8 @@ ngramsView props = R.createElement ngramsViewCpt props [] ...@@ -63,7 +65,8 @@ ngramsView props = R.createElement ngramsViewCpt props []
ngramsViewCpt :: R.Component NgramsViewProps ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
where where
cpt { asyncTasksRef cpt { appReload
, asyncTasksRef
, cacheState , cacheState
, corpusData: { defaultListId } , corpusData: { defaultListId }
, corpusId , corpusId
...@@ -76,6 +79,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt ...@@ -76,6 +79,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
pure $ R.fragment pure $ R.fragment
( charts tabNgramType chartType chartsReload ( charts tabNgramType chartType chartsReload
<> [ NT.mainNgramsTable { afterSync: afterSync chartsReload <> [ NT.mainNgramsTable { afterSync: afterSync chartsReload
, appReload
, asyncTasksRef , asyncTasksRef
, cacheState , cacheState
, defaultListId , defaultListId
......
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