Commit 62c3fb5b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] some (incomplete) work on caching charts with async tasks

parent 51dd886f
...@@ -5,7 +5,7 @@ import Data.Argonaut.Parser (jsonParser) ...@@ -5,7 +5,7 @@ import Data.Argonaut.Parser (jsonParser)
import Data.Array as A import Data.Array as A
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Tuple (snd) import Data.Tuple (snd)
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
...@@ -41,6 +41,9 @@ getAsyncTasks = R2.getls >>= WSS.getItem localStorageKey >>= handleMaybe ...@@ -41,6 +41,9 @@ getAsyncTasks = R2.getls >>= WSS.getItem localStorageKey >>= handleMaybe
parse s = GU.mapLeft (log2 "Error parsing serialised sessions:") (jsonParser s) parse s = GU.mapLeft (log2 "Error parsing serialised sessions:") (jsonParser s)
decode j = GU.mapLeft (log2 "Error decoding serialised sessions:") (decodeJson j) decode j = GU.mapLeft (log2 "Error decoding serialised sessions:") (decodeJson j)
getTasks :: Record ReductorProps -> NodeId -> Array GT.AsyncTaskWithType
getTasks { storage } nodeId = fromMaybe [] $ Map.lookup nodeId storage
removeTaskFromList :: Array GT.AsyncTaskWithType -> GT.AsyncTaskWithType -> Array GT.AsyncTaskWithType removeTaskFromList :: Array GT.AsyncTaskWithType -> GT.AsyncTaskWithType -> Array GT.AsyncTaskWithType
removeTaskFromList ts (GT.AsyncTaskWithType { task: GT.AsyncTask { id: id' } }) = removeTaskFromList ts (GT.AsyncTaskWithType { task: GT.AsyncTask { id: id' } }) =
A.filter (\(GT.AsyncTaskWithType { task: GT.AsyncTask { id: id'' } }) -> id' /= id'') ts A.filter (\(GT.AsyncTaskWithType { task: GT.AsyncTask { id: id'' } }) -> id' /= id'') ts
...@@ -50,20 +53,27 @@ type ReductorProps = ( ...@@ -50,20 +53,27 @@ type ReductorProps = (
, storage :: Storage , storage :: Storage
) )
useTasks :: R.State Int -> R.Hooks (R2.Reductor (Record ReductorProps) Action) type Reductor = R2.Reductor (Record ReductorProps) Action
useTasks reload = R2.useReductor act (const { reload, storage: getAsyncTasks }) unit
useTasks :: R.State Int -> R.Hooks Reductor
useTasks reload = R2.useReductor act initializer unit
where where
act :: R2.Actor (Record ReductorProps) Action act :: R2.Actor (Record ReductorProps) Action
act a s = action s a act a s = action s a
initializer _ = do
storage <- getAsyncTasks
pure { reload, storage }
data Action = data Action =
Insert NodeId GT.AsyncTaskWithType Insert NodeId GT.AsyncTaskWithType
| Remove NodeId GT.AsyncTaskWithType | Remove NodeId GT.AsyncTaskWithType
action :: Record ReductorProps -> Action -> Effect Storage action :: Record ReductorProps -> Action -> Effect (Record ReductorProps)
action { reload, storage } (Insert id t) = do action { reload, storage } (Insert nodeId t) = do
snd reload $ (_ + 1) _ <- snd reload $ (_ + 1)
pure $ Map.alter (maybe (Just [t]) (\ts -> Just $ A.cons t ts)) id storage let newStorage = Map.alter (maybe (Just [t]) (\ts -> Just $ A.cons t ts)) nodeId storage
action { reload, storage } (Remove id t) = do pure { reload, storage: newStorage }
snd reload $ (_ + 1) action { reload, storage } (Remove nodeId t) = do
pure $ Map.alter (maybe Nothing $ (\ts -> Just $ removeTaskFromList ts t)) id storage _ <- snd reload $ (_ + 1)
let newStorage = Map.alter (maybe Nothing $ (\ts -> Just $ removeTaskFromList ts t)) nodeId storage
pure { reload, storage: newStorage }
...@@ -55,13 +55,13 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -55,13 +55,13 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
showLogin <- R.useState' false showLogin <- R.useState' false
backend <- R.useState' Nothing backend <- R.useState' Nothing
showCorpus <- R.useState' false
treeReload <- R.useState' 0 treeReload <- R.useState' 0
handed <- R.useState' GT.RightHanded asyncTasks <- GAT.useTasks treeReload
asyncTasks <- R2.useLocalStorageState GAT.localStorageKey GAT.empty showCorpus <- R.useState' false
handed <- R.useState' GT.RightHanded
let backends = fromFoldable defaultBackends let backends = fromFoldable defaultBackends
let ff f session = R.fragment [ f session, footer { session } ] let ff f session = R.fragment [ f session, footer { session } ]
...@@ -128,7 +128,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -128,7 +128,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout { asyncTasks, frontends, nodeId, session } UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout { asyncTasks, frontends, nodeId, session }
type ForestLayoutProps = type ForestLayoutProps =
( asyncTasks :: R.State GAT.Storage ( asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend) , backend :: R.State (Maybe Backend)
, child :: R.Element , child :: R.Element
, frontends :: Frontends , frontends :: Frontends
......
...@@ -259,9 +259,9 @@ mock :: Boolean ...@@ -259,9 +259,9 @@ mock :: Boolean
mock = false mock = false
type PageParams = type PageParams =
{ nodeId :: Int { corpusId :: Maybe Int
, listId :: Int , listId :: Int
, corpusId :: Maybe Int , nodeId :: Int
, tabType :: TabType , tabType :: TabType
, query :: Query , query :: Query
, params :: T.Params} , params :: T.Params}
......
...@@ -22,7 +22,7 @@ thisModule :: String ...@@ -22,7 +22,7 @@ thisModule :: String
thisModule = "Gargantext.Components.Forest" thisModule = "Gargantext.Components.Forest"
type Props = type Props =
( asyncTasks :: R.State GAT.Storage ( asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend) , backend :: R.State (Maybe Backend)
, frontends :: Frontends , frontends :: Frontends
, handed :: Handed , handed :: Handed
...@@ -48,7 +48,7 @@ forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where ...@@ -48,7 +48,7 @@ forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where
/\ fst openNodes /\ fst openNodes
/\ fst extReload /\ fst extReload
/\ fst reload /\ fst reload
/\ fst asyncTasks /\ (fst asyncTasks).storage
/\ handed /\ handed
) )
(cpt' openNodes asyncTasks reload showLogin backend) (cpt' openNodes asyncTasks reload showLogin backend)
......
...@@ -28,7 +28,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Contact as Contact ...@@ -28,7 +28,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Contact as Contact
import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest) import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile, uploadArbitraryFile) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile, uploadArbitraryFile)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..)) import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools.Task (Tasks, tasksStruct)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, discard, map, pure, void, ($), (+), (<>), (==), (<<<), not) import Gargantext.Prelude (Unit, bind, discard, map, pure, void, ($), (+), (<>), (==), (<<<), not)
...@@ -52,7 +51,7 @@ type CommonProps = ...@@ -52,7 +51,7 @@ type CommonProps =
) )
------------------------------------------------------------------------ ------------------------------------------------------------------------
type Props = ( asyncTasks :: R.State GAT.Storage type Props = ( asyncTasks :: GAT.Reductor
, root :: ID , root :: ID
| CommonProps | CommonProps
) )
...@@ -105,7 +104,7 @@ treeLoadView p = R.createElement treeLoadViewCpt p [] ...@@ -105,7 +104,7 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
, openNodes , openNodes
, reload , reload
, session , session
, tasks: tasksStruct root asyncTasks reload -- , tasks: tasksStruct root asyncTasks reload
, tree: loaded , tree: loaded
} }
useLoader { root, counter: fst reload } fetch paint useLoader { root, counter: fst reload } fetch paint
...@@ -115,8 +114,7 @@ getNodeTree :: Session -> GT.ID -> Aff FTree ...@@ -115,8 +114,7 @@ getNodeTree :: Session -> GT.ID -> Aff FTree
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) "" getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
-------------- --------------
type TreeViewProps = ( asyncTasks :: R.State GAT.Storage type TreeViewProps = ( asyncTasks :: GAT.Reductor
, tasks :: Record Tasks
, tree :: FTree , tree :: FTree
| CommonProps | CommonProps
) )
...@@ -134,7 +132,7 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p [] ...@@ -134,7 +132,7 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
, openNodes , openNodes
, reload , reload
, session , session
, tasks -- , tasks
, tree , tree
} _ = pure $ H.ul { className: "tree" } _ = pure $ H.ul { className: "tree"
} }
...@@ -149,7 +147,7 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p [] ...@@ -149,7 +147,7 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
, openNodes , openNodes
, reload , reload
, session , session
, tasks -- , tasks
, tree , tree
} }
] ]
...@@ -159,38 +157,39 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p [] ...@@ -159,38 +157,39 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
type ToHtmlProps = type ToHtmlProps =
( asyncTasks :: R.State GAT.Storage ( asyncTasks :: GAT.Reductor
, tasks :: Record Tasks -- , tasks :: Record Tasks
, tree :: FTree , tree :: FTree
| CommonProps | CommonProps
) )
toHtml :: Record ToHtmlProps -> R.Element toHtml :: Record ToHtmlProps -> R.Element
toHtml p@{ asyncTasks toHtml p = R.createElement toHtmlCpt p []
, frontends
, handed toHtmlCpt :: R.Component ToHtmlProps
, mCurrentRoute toHtmlCpt = R.hooksComponentWithModule thisModule "nodeView" cpt
, openNodes
, reload: reload@(_ /\ setReload)
, session
, tasks: tasks@{ onTaskAdd
, onTaskFinish
, tasks: tasks'
}
, tree: tree@(NTree (LNode { id
, name
, nodeType
}
) ary
)
} =
R.createElement el {} []
where where
el = R.hooksComponentWithModule thisModule "nodeView" cpt cpt p@{ asyncTasks
commonProps = RecordE.pick p :: Record CommonProps , frontends
pAction a = performAction a (RecordE.pick p :: Record PerformActionProps) , handed
, mCurrentRoute
, openNodes
, reload: reload@(_ /\ setReload)
, session
-- , tasks: tasks@{ onTaskAdd
-- , onTaskFinish
-- , tasks: tasks'
-- }
, tree: tree@(NTree (LNode { id
, name
, nodeType
}
) ary
)
} _ = do
let commonProps = RecordE.pick p :: Record CommonProps
let pAction a = performAction a (RecordE.pick p :: Record PerformActionProps)
cpt _ _ = do
let nodeId = mkNodeId session id let nodeId = mkNodeId session id
let folderIsOpen = Set.member nodeId (fst openNodes) let folderIsOpen = Set.member nodeId (fst openNodes)
let setFn = if folderIsOpen then Set.delete else Set.insert let setFn = if folderIsOpen then Set.delete else Set.insert
...@@ -200,17 +199,18 @@ toHtml p@{ asyncTasks ...@@ -200,17 +199,18 @@ toHtml p@{ asyncTasks
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 (A.null ary) [ nodeMainSpan { asyncTasks
{ dispatch: pAction , dispatch: pAction
, folderOpen , folderOpen
, frontends , frontends
, handed , handed
, id , id
, isLeaf: A.null ary
, mCurrentRoute , mCurrentRoute
, name , name
, nodeType , nodeType
, session , session
, tasks -- , tasks
} ] } ]
<> childNodes ( Record.merge commonProps <> childNodes ( Record.merge commonProps
{ asyncTasks { asyncTasks
...@@ -226,7 +226,7 @@ toHtml p@{ asyncTasks ...@@ -226,7 +226,7 @@ toHtml p@{ asyncTasks
type ChildNodesProps = type ChildNodesProps =
( asyncTasks :: R.State GAT.Storage ( asyncTasks :: GAT.Reductor
, children :: Array FTree , children :: Array FTree
, folderOpen :: R.State Boolean , folderOpen :: R.State Boolean
| CommonProps | CommonProps
...@@ -239,7 +239,7 @@ childNodes props@{ asyncTasks, children, reload, handed } = ...@@ -239,7 +239,7 @@ childNodes props@{ asyncTasks, children, reload, handed } =
map (\ctree@(NTree (LNode {id}) _) -> H.ul {} [ map (\ctree@(NTree (LNode {id}) _) -> H.ul {} [
toHtml (Record.merge commonProps { asyncTasks toHtml (Record.merge commonProps { asyncTasks
, handed , handed
, tasks: tasksStruct id asyncTasks reload -- , tasks: tasksStruct id asyncTasks reload
, tree: ctree , tree: ctree
} }
)] )]
...@@ -250,10 +250,11 @@ childNodes props@{ asyncTasks, children, reload, handed } = ...@@ -250,10 +250,11 @@ childNodes props@{ asyncTasks, children, reload, handed } =
sorted = A.sortWith (\(NTree (LNode {id}) _) -> id) sorted = A.sortWith (\(NTree (LNode {id}) _) -> id)
type PerformActionProps = type PerformActionProps =
( openNodes :: R.State OpenNodes ( asyncTasks :: GAT.Reductor
, openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
, session :: Session , session :: Session
, tasks :: Record Tasks -- , tasks :: Record Tasks
, tree :: FTree , tree :: FTree
) )
...@@ -276,24 +277,23 @@ performAction (DeleteNode nt) p@{ openNodes: (_ /\ setOpenNodes) ...@@ -276,24 +277,23 @@ performAction (DeleteNode nt) p@{ openNodes: (_ /\ setOpenNodes)
performAction RefreshTree p performAction RefreshTree p
------- -------
performAction (DoSearch task) { reload: (_ /\ setReload) performAction (DoSearch task) { asyncTasks: (_ /\ dispatch)
, session , session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
liftEffect $ onTaskAdd task liftEffect $ dispatch $ GAT.Insert id task
liftEffect $ log2 "[performAction] DoSearch task:" task liftEffect $ log2 "[performAction] DoSearch task:" task
------- -------
performAction (UpdateNode params) { reload: (_ /\ setReload) performAction (UpdateNode params) { asyncTasks: (_ /\ dispatch)
, session , session
, tasks: {onTaskAdd} -- , tasks: {onTaskAdd}
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
task <- updateRequest params session id task <- updateRequest params session id
liftEffect $ onTaskAdd task liftEffect $ dispatch $ GAT.Insert id task
liftEffect $ log2 "[performAction] UpdateNode task:" task liftEffect $ log2 "[performAction] UpdateNode task:" task
...@@ -346,22 +346,22 @@ performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes) ...@@ -346,22 +346,22 @@ performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes)
performAction RefreshTree p performAction RefreshTree p
------- -------
performAction (UploadFile nodeType fileType mName blob) { session performAction (UploadFile nodeType fileType mName blob) { asyncTasks: (_ /\ dispatch)
, tasks: { onTaskAdd } , session
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
task <- uploadFile session nodeType id fileType {mName, blob} task <- uploadFile session nodeType id fileType {mName, blob}
liftEffect $ onTaskAdd task liftEffect $ dispatch $ GAT.Insert id task
liftEffect $ log2 "Uploaded, task:" task liftEffect $ log2 "Uploaded, task:" task
performAction (UploadArbitraryFile mName blob) { session performAction (UploadArbitraryFile mName blob) { asyncTasks: (_ /\ dispatch)
, tasks: { onTaskAdd } , session
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
task <- uploadArbitraryFile session id { blob, mName } task <- uploadArbitraryFile session id { blob, mName }
liftEffect $ onTaskAdd task liftEffect $ dispatch $ GAT.Insert id task
liftEffect $ log2 "Uploaded, task:" task liftEffect $ log2 "Uploaded, task:" task
------- -------
......
...@@ -10,6 +10,9 @@ import React.SyntheticEvent as E ...@@ -10,6 +10,9 @@ import React.SyntheticEvent as E
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree.Node.Settings (SettingsBox(..), settingsBox) import Gargantext.Components.Forest.Tree.Node.Settings (SettingsBox(..), settingsBox)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..)) import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..))
...@@ -17,7 +20,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Upload (DroppedFile(..), fi ...@@ -17,7 +20,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Upload (DroppedFile(..), fi
import Gargantext.Components.Forest.Tree.Node.Box (nodePopupView) import Gargantext.Components.Forest.Tree.Node.Box (nodePopupView)
import Gargantext.Components.Forest.Tree.Node.Box.Types (CommonProps) import Gargantext.Components.Forest.Tree.Node.Box.Types (CommonProps)
import Gargantext.Components.Forest.Tree.Node.Tools.ProgressBar (asyncProgressBar, BarType(..)) import Gargantext.Components.Forest.Tree.Node.Tools.ProgressBar (asyncProgressBar, BarType(..))
import Gargantext.Components.Forest.Tree.Node.Tools.Task (Tasks)
import Gargantext.Components.Forest.Tree.Node.Tools.Sync (nodeActionsGraph, nodeActionsNodeList) import Gargantext.Components.Forest.Tree.Node.Tools.Sync (nodeActionsGraph, nodeActionsNodeList)
import Gargantext.Components.Forest.Tree.Node.Tools (nodeLink) import Gargantext.Components.Forest.Tree.Node.Tools (nodeLink)
import Gargantext.Components.GraphExplorer.API as GraphAPI import Gargantext.Components.GraphExplorer.API as GraphAPI
...@@ -25,7 +27,6 @@ import Gargantext.Components.Lang (Lang(EN)) ...@@ -25,7 +27,6 @@ import Gargantext.Components.Lang (Lang(EN))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild) import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, const, discard, map, pure, show, unit, void, ($), (<>), (==), identity)
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Version as GV import Gargantext.Version as GV
import Gargantext.Sessions (Session, sessionId) import Gargantext.Sessions (Session, sessionId)
...@@ -34,30 +35,44 @@ import Gargantext.Types as GT ...@@ -34,30 +35,44 @@ import Gargantext.Types as GT
import Gargantext.Utils.Popover as Popover import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node" thisModule = "Gargantext.Components.Forest.Tree.Node"
-- Main Node -- Main Node
type NodeMainSpanProps = type NodeMainSpanProps =
( id :: ID ( asyncTasks :: GAT.Reductor
, folderOpen :: R.State Boolean , folderOpen :: R.State Boolean
, frontends :: Frontends , frontends :: Frontends
, id :: ID
, isLeaf :: IsLeaf
, mCurrentRoute :: Maybe Routes.AppRoute , mCurrentRoute :: Maybe Routes.AppRoute
, name :: Name , name :: Name
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, tasks :: Record Tasks
| CommonProps | CommonProps
) )
type IsLeaf = Boolean type IsLeaf = Boolean
nodeMainSpan :: IsLeaf nodeMainSpan :: Record NodeMainSpanProps
-> Record NodeMainSpanProps
-> R.Element -> R.Element
nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.createElement el p [] nodeMainSpan p = R.createElement nodeMainSpanCpt p []
nodeMainSpanCpt :: R.Component NodeMainSpanProps
nodeMainSpanCpt = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt
where where
el = R.hooksComponentWithModule thisModule "nodeMainSpan" cpt cpt props@{ asyncTasks: (asyncTasks /\ dispatchAsyncTasks)
cpt props@{id, mCurrentRoute, name, nodeType, tasks: { onTaskFinish, tasks }} _ = do , dispatch
, folderOpen
, frontends
, handed
, id
, isLeaf
, mCurrentRoute
, name
, nodeType
, session
} _ = do
-- only 1 popup at a time is allowed to be opened -- only 1 popup at a time is allowed to be opened
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile) droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
isDragOver <- R.useState' false isDragOver <- R.useState' false
...@@ -69,31 +84,30 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c ...@@ -69,31 +84,30 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c
GT.LeftHanded -> reverse GT.LeftHanded -> reverse
GT.RightHanded -> identity GT.RightHanded -> identity
let isSelected = mCurrentRoute == Routes.nodeTypeAppRoute nodeType (sessionId session) id
pure $ H.span (dropProps droppedFile isDragOver) pure $ H.span (dropProps droppedFile isDragOver)
$ ordering $ ordering
[ folderIcon nodeType folderOpen [ folderIcon nodeType folderOpen
, chevronIcon isLeaf handed nodeType folderOpen , chevronIcon isLeaf handed nodeType folderOpen
, nodeLink { frontends , nodeLink { frontends
, id , handed
, folderOpen , folderOpen
, isSelected: mCurrentRoute , id
== Routes.nodeTypeAppRoute , isSelected
nodeType
(sessionId session) id
, name: name' props , name: name' props
, nodeType , nodeType
, session , session
, handed
} }
, fileTypeView { dispatch, droppedFile, id, isDragOver, nodeType } , fileTypeView { dispatch, droppedFile, id, isDragOver, nodeType }
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t , H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, barType: Pie , barType: Pie
, corpusId: id , nodeId: id
, onFinish: const $ onTaskFinish t , onFinish: const $ dispatchAsyncTasks $ GAT.Remove id t
, session , session
} }
) tasks ) $ GAT.getTasks asyncTasks id
) )
, if nodeType == GT.NodeUser , if nodeType == GT.NodeUser
then GV.versionView {session} then GV.versionView {session}
...@@ -119,20 +133,28 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c ...@@ -119,20 +133,28 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c
] ]
where where
SettingsBox {show: showBox} = settingsBox nodeType SettingsBox {show: showBox} = settingsBox nodeType
onPopoverClose popoverRef _ = Popover.setOpen popoverRef false onPopoverClose popoverRef _ = Popover.setOpen popoverRef false
name' {name, nodeType} = if nodeType == GT.NodeUser name' {name, nodeType} = if nodeType == GT.NodeUser then show session else name
then show session
else name mNodePopupView props@{id, nodeType} onPopoverClose =
nodePopupView { dispatch
chevronIcon isLeaf handed' nodeType folderOpen'@(open /\ _) = , handed : props.handed
, id
, name: name' props
, nodeType
, onPopoverClose
, session
}
chevronIcon isLeaf handed' nodeType (open /\ setOpen) =
if isLeaf if isLeaf
then H.div {} [] then H.div {} []
else else
H.a { className: "chevron-icon" H.a { className: "chevron-icon"
, onClick: R2.effToggler folderOpen' , on: { click: \_ -> setOpen $ not }
} }
[ H.i { [ H.i {
className: if open className: if open
...@@ -142,28 +164,18 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c ...@@ -142,28 +164,18 @@ nodeMainSpan isLeaf p@{ dispatch, folderOpen, frontends, handed, session } = R.c
else "fa fa-chevron-left" else "fa fa-chevron-left"
} [] ] } [] ]
folderIcon nodeType folderOpen'@(open /\ _) = folderIcon nodeType (open /\ setOpen) =
H.a { className: "folder-icon" H.a { className: "folder-icon"
, onClick: R2.effToggler folderOpen' , on: { click: \_ -> setOpen $ not }
} [ } [
H.i {className: GT.fldr nodeType open} [] H.i {className: GT.fldr nodeType open} []
] ]
popOverIcon = H.a { className: "settings fa fa-cog" popOverIcon = H.a { className: "settings fa fa-cog"
, title : "Each node of the Tree can perform some actions.\n" , title : "Each node of the Tree can perform some actions.\n"
<> "Click here to execute one of them." <> "Click here to execute one of them."
} [] } []
mNodePopupView props@{id, nodeType} onPopoverClose =
nodePopupView { id
, dispatch
, name: name' props
, nodeType
, onPopoverClose
, session
, handed : props.handed
}
dropProps droppedFile isDragOver = dropProps droppedFile isDragOver =
{ className: "leaf " <> (dropClass droppedFile isDragOver) { className: "leaf " <> (dropClass droppedFile isDragOver)
, on: { drop: dropHandler droppedFile , on: { drop: dropHandler droppedFile
......
...@@ -282,11 +282,19 @@ nodeLink p = R.createElement nodeLinkCpt p [] ...@@ -282,11 +282,19 @@ nodeLink p = R.createElement nodeLinkCpt p []
nodeLinkCpt :: R.Component NodeLinkProps nodeLinkCpt :: R.Component NodeLinkProps
nodeLinkCpt = R.hooksComponentWithModule thisModule "nodeLink" cpt nodeLinkCpt = R.hooksComponentWithModule thisModule "nodeLink" cpt
where where
cpt { frontends, id, isSelected, name, nodeType, session, handed, folderOpen} _ = do cpt { folderOpen: (_ /\ setFolderOpen)
, frontends
, handed
, id
, isSelected
, name
, nodeType
, session
} _ = do
popoverRef <- R.useRef null popoverRef <- R.useRef null
pure $ pure $
H.div { onClick: R2.effToggler folderOpen } H.div { on: { click: \_ -> setFolderOpen $ not } }
[ H.a { data: { for: tooltipId [ H.a { data: { for: tooltipId
, tip: true , tip: true
} }
......
...@@ -16,15 +16,16 @@ import Gargantext.Sessions (Session, get) ...@@ -16,15 +16,16 @@ import Gargantext.Sessions (Session, get)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node.Tools.ProgressBar" thisModule = "Gargantext.Components.Forest.Tree.Node.Tools.ProgressBar"
data BarType = Bar | Pie data BarType = Bar | Pie
type Props = type Props = (
( asyncTask :: GT.AsyncTaskWithType asyncTask :: GT.AsyncTaskWithType
, barType :: BarType , barType :: BarType
, corpusId :: GT.ID , nodeId :: GT.ID
, onFinish :: Unit -> Effect Unit , onFinish :: Unit -> Effect Unit
, session :: Session , session :: Session
) )
...@@ -38,7 +39,7 @@ asyncProgressBarCpt = R.hooksComponentWithModule thisModule "asyncProgressBar" c ...@@ -38,7 +39,7 @@ asyncProgressBarCpt = R.hooksComponentWithModule thisModule "asyncProgressBar" c
where where
cpt props@{ asyncTask: (GT.AsyncTaskWithType {task: GT.AsyncTask {id}}) cpt props@{ asyncTask: (GT.AsyncTaskWithType {task: GT.AsyncTask {id}})
, barType , barType
, corpusId , nodeId
, onFinish , onFinish
} _ = do } _ = do
(progress /\ setProgress) <- R.useState' 0.0 (progress /\ setProgress) <- R.useState' 0.0
...@@ -104,13 +105,14 @@ queryProgress :: Record Props -> Aff GT.AsyncProgress ...@@ -104,13 +105,14 @@ queryProgress :: Record Props -> Aff GT.AsyncProgress
queryProgress { asyncTask: GT.AsyncTaskWithType { task: GT.AsyncTask {id} queryProgress { asyncTask: GT.AsyncTaskWithType { task: GT.AsyncTask {id}
, typ , typ
} }
, corpusId , nodeId
, session , session
} = get session (p typ) } = get session (p typ)
where where
-- TODO refactor path -- TODO refactor path
p GT.UpdateNode = NodeAPI GT.Node (Just corpusId) $ path <> id <> "/poll?limit=1" p GT.UpdateNode = NodeAPI GT.Node (Just nodeId) $ path <> id <> "/poll?limit=1"
p _ = NodeAPI GT.Corpus (Just corpusId) $ path <> id <> "/poll?limit=1" p GT.UpdateNgramsCharts = NodeAPI GT.Node (Just nodeId) $ path <> id <> "/poll?limit=1"
p _ = NodeAPI GT.Corpus (Just nodeId) $ path <> id <> "/poll?limit=1"
path = GT.asyncTaskTypePath typ path = GT.asyncTaskTypePath typ
-- TODO wait route: take the result if failure then message -- TODO wait route: take the result if failure then message
...@@ -6,11 +6,12 @@ import Data.Map as Map ...@@ -6,11 +6,12 @@ import Data.Map as Map
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Reactix as R
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Prelude (Unit, discard, identity, ($), (+)) import Gargantext.Prelude (Unit, discard, identity, ($), (+))
import Gargantext.Types (Reload) import Gargantext.Types (Reload)
import Gargantext.Types as GT import Gargantext.Types as GT
import Reactix as R
type Tasks = type Tasks =
...@@ -20,19 +21,14 @@ type Tasks = ...@@ -20,19 +21,14 @@ type Tasks =
) )
tasksStruct :: Int tasksStruct :: Int
-> R.State GAT.Storage -> GAT.Reductor
-> R.State Reload -> R.State Reload
-> Record Tasks -> Record Tasks
tasksStruct id (asyncTasks /\ setAsyncTasks) (_ /\ setReload) = tasksStruct id ({ storage } /\ dispatch) (_ /\ setReload) =
{ onTaskAdd, onTaskFinish, tasks } { onTaskAdd, onTaskFinish, tasks }
where where
tasks = maybe [] identity $ Map.lookup id asyncTasks tasks = maybe [] identity $ Map.lookup id storage
onTaskAdd t = do onTaskAdd t = dispatch $ GAT.Insert id t
setReload (_ + 1)
setAsyncTasks $ Map.alter (maybe (Just [t])
$ (\ts -> Just $ A.cons t ts)) id
onTaskFinish t = do onTaskFinish t = dispatch $ GAT.Remove id t
setReload (_ + 1)
setAsyncTasks $ Map.alter (maybe Nothing $ (\ts -> Just $ GAT.removeTaskFromList ts t)) id
...@@ -41,8 +41,9 @@ import Gargantext.Utils.Reactix as R2 ...@@ -41,8 +41,9 @@ import Gargantext.Utils.Reactix as R2
thisModule :: String thisModule :: String
thisModule = "Gargantext.Components.GraphExplorer" thisModule = "Gargantext.Components.GraphExplorer"
type LayoutProps = type LayoutProps = (
( asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend)
, frontends :: Frontends , frontends :: Frontends
, graphId :: GET.GraphId , graphId :: GET.GraphId
, handed :: Types.Handed , handed :: Types.Handed
...@@ -50,7 +51,6 @@ type LayoutProps = ...@@ -50,7 +51,6 @@ type LayoutProps =
, session :: Session , session :: Session
, sessions :: Sessions , sessions :: Sessions
, showLogin :: R.State Boolean , showLogin :: R.State Boolean
, backend :: R.State (Maybe Backend)
) )
type Props = type Props =
...@@ -226,7 +226,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt ...@@ -226,7 +226,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
type TreeProps = type TreeProps =
( (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, backend :: R.State (Maybe Backend) , backend :: R.State (Maybe Backend)
, frontends :: Frontends , frontends :: Frontends
, handed :: Types.Handed , handed :: Types.Handed
......
...@@ -20,7 +20,7 @@ import Data.Sequence as Seq ...@@ -20,7 +20,7 @@ import Data.Sequence as Seq
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import Effect (Effect) import Effect (Effect)
...@@ -279,13 +279,13 @@ tableContainerCpt { dispatch ...@@ -279,13 +279,13 @@ tableContainerCpt { dispatch
] ]
-- NEXT -- NEXT
type Props = type Props = (
( afterSync :: Unit -> Aff Unit afterSync :: Unit -> Aff Unit
, asyncTasks :: R.State GAT.Storage , asyncTasks :: GAT.Reductor
, path :: R.State PageParams , path :: R.State PageParams
, state :: R.State State , state :: R.State State
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
, versioned :: VersionedNgramsTable , versioned :: VersionedNgramsTable
, withAutoUpdate :: Boolean , withAutoUpdate :: Boolean
) )
...@@ -297,7 +297,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" ...@@ -297,7 +297,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
where where
cpt { afterSync cpt { afterSync
, asyncTasks , asyncTasks
, path: path@(path'@{ searchQuery, scoreType, params, termListFilter, termSizeFilter } /\ setPath) , path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath)
, state: (state@{ ngramsChildren , state: (state@{ ngramsChildren
, ngramsLocalPatch , ngramsLocalPatch
, ngramsParent , ngramsParent
...@@ -367,6 +367,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" ...@@ -367,6 +367,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
task <- postNgramsChartsAsync path' task <- postNgramsChartsAsync path'
liftEffect $ do liftEffect $ do
log2 "[performAction] Synchronize task" task log2 "[performAction] Synchronize task" task
snd asyncTasks $ GAT.Insert nodeId task
performAction (CommitPatch pt) = performAction (CommitPatch pt) =
commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState) commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
performAction ResetPatches = performAction ResetPatches =
...@@ -529,7 +530,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng ...@@ -529,7 +530,7 @@ selectNgramsOnFirstPage rows = Set.fromFoldable $ (view $ _NgramsElement <<< _ng
type MainNgramsTableProps = ( type MainNgramsTableProps = (
afterSync :: Unit -> Aff Unit afterSync :: Unit -> Aff Unit
, asyncTasks :: R.State GAT.Storage , asyncTasks :: GAT.Reductor
, cacheState :: R.State NT.CacheState , cacheState :: R.State NT.CacheState
, defaultListId :: Int , defaultListId :: Int
, nodeId :: Int , nodeId :: Int
...@@ -606,7 +607,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt ...@@ -606,7 +607,7 @@ mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
type MainNgramsTablePaintProps = ( type MainNgramsTablePaintProps = (
afterSync :: Unit -> Aff Unit afterSync :: Unit -> Aff Unit
, asyncTasks :: R.State GAT.Storage , asyncTasks :: GAT.Reductor
, path :: PageParams , path :: PageParams
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
, versioned :: VersionedNgramsTable , versioned :: VersionedNgramsTable
......
...@@ -146,7 +146,7 @@ infoRender (Tuple title content) = ...@@ -146,7 +146,7 @@ infoRender (Tuple title content) =
, H.span {} [H.text content] ] , H.span {} [H.text content] ]
type LayoutProps = ( type LayoutProps = (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, frontends :: Frontends , frontends :: Frontends
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
......
...@@ -45,7 +45,7 @@ modeTabType' Books = CTabAuthors ...@@ -45,7 +45,7 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors modeTabType' Communication = CTabAuthors
type TabsProps = ( type TabsProps = (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, contactData :: ContactData , contactData :: ContactData
, frontends :: Frontends , frontends :: Frontends
...@@ -86,7 +86,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -86,7 +86,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
type NgramsViewTabsProps = ( type NgramsViewTabsProps = (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, defaultListId :: Int , defaultListId :: Int
, mode :: Mode , mode :: Mode
......
...@@ -24,7 +24,7 @@ thisModule = "Gargantext.Components.Nodes.Lists" ...@@ -24,7 +24,7 @@ thisModule = "Gargantext.Components.Nodes.Lists"
------------------------------------------------------------------------ ------------------------------------------------------------------------
type Props = ( type Props = (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
, sessionUpdate :: Session -> Effect Unit , sessionUpdate :: Session -> Effect Unit
......
...@@ -29,7 +29,7 @@ thisModule :: String ...@@ -29,7 +29,7 @@ thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists.Tabs" thisModule = "Gargantext.Components.Nodes.Lists.Tabs"
type Props = ( type Props = (
asyncTasks :: R.State GAT.Storage asyncTasks :: GAT.Reductor
, cacheState :: R.State NTypes.CacheState , cacheState :: R.State NTypes.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: Int , corpusId :: Int
......
...@@ -109,9 +109,6 @@ select = createDOM "select" ...@@ -109,9 +109,6 @@ select = createDOM "select"
menu :: ElemFactory menu :: ElemFactory
menu = createDOM "menu" menu = createDOM "menu"
effToggler :: forall e. R.State Boolean -> EffectFn1 e Unit
effToggler (value /\ setValue) = mkEffectFn1 $ \_ -> setValue $ const $ not value
keyCode :: forall event. event -> Effect Int keyCode :: forall event. event -> Effect Int
keyCode = runEffectFn1 _keyCode keyCode = runEffectFn1 _keyCode
......
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