Commit f5589c05 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[tree] more props rewriting

parent eabde0f4
...@@ -20,13 +20,18 @@ import Gargantext.Types as GT ...@@ -20,13 +20,18 @@ import Gargantext.Types as GT
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
------------------------------------------------------------------------ type CommonProps =
type Props = ( root :: ID (
frontends :: Frontends
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, session :: Session
, frontends :: Frontends
, openNodes :: R.State OpenNodes , openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
, session :: Session
)
------------------------------------------------------------------------
type Props = ( root :: ID
| CommonProps
) )
treeView :: Record Props -> R.Element treeView :: Record Props -> R.Element
...@@ -39,18 +44,10 @@ treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt ...@@ -39,18 +44,10 @@ treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt
pure $ treeLoadView pure $ treeLoadView
{ root, mCurrentRoute, session, frontends, openNodes, reload } { root, mCurrentRoute, session, frontends, openNodes, reload }
type Props' = ( root :: ID treeLoadView :: Record Props -> R.Element
, mCurrentRoute :: Maybe AppRoute
, session :: Session
, frontends :: Frontends
, openNodes :: R.State OpenNodes
, reload :: R.State Reload
)
treeLoadView :: Record Props' -> R.Element
treeLoadView p = R.createElement treeLoadView' p [] treeLoadView p = R.createElement treeLoadView' p []
treeLoadView' :: R.Component Props' treeLoadView' :: R.Component Props
treeLoadView' = R.hooksComponent "TreeLoadView" cpt treeLoadView' = R.hooksComponent "TreeLoadView" cpt
where where
cpt {root, mCurrentRoute, session, frontends, openNodes, reload} _ = do cpt {root, mCurrentRoute, session, frontends, openNodes, reload} _ = do
...@@ -59,11 +56,7 @@ treeLoadView' = R.hooksComponent "TreeLoadView" cpt ...@@ -59,11 +56,7 @@ treeLoadView' = R.hooksComponent "TreeLoadView" cpt
useLoader {root, counter: fst reload} fetch paint useLoader {root, counter: fst reload} fetch paint
type TreeViewProps = ( tree :: FTree type TreeViewProps = ( tree :: FTree
, mCurrentRoute :: Maybe AppRoute | CommonProps
, frontends :: Frontends
, session :: Session
, openNodes :: R.State OpenNodes
, reload :: R.State Reload
) )
...@@ -83,13 +76,9 @@ loadedTreeView' = R.hooksComponent "LoadedTreeView" cpt ...@@ -83,13 +76,9 @@ loadedTreeView' = R.hooksComponent "LoadedTreeView" cpt
type ToHtmlProps = type ToHtmlProps =
( (
frontends :: Frontends tasks :: R.State (Array GT.AsyncTaskWithType)
, mCurrentRoute :: Maybe AppRoute
, openNodes :: R.State OpenNodes
, reload :: R.State Reload
, session :: Session
, tasks :: R.State (Array GT.AsyncTaskWithType)
, tree :: FTree , tree :: FTree
| CommonProps
) )
toHtml :: Record ToHtmlProps -> R.Element toHtml :: Record ToHtmlProps -> R.Element
...@@ -122,7 +111,7 @@ toHtml { frontends ...@@ -122,7 +111,7 @@ toHtml { frontends
, nodeType , nodeType
, onAsyncTaskFinish , onAsyncTaskFinish
} folderOpen session frontends ] } folderOpen session frontends ]
<> childNodes session frontends reload folderOpen mCurrentRoute openNodes ary <> childNodes {children: ary, folderOpen, frontends, mCurrentRoute, openNodes, reload, session }
) )
] ]
...@@ -133,18 +122,19 @@ toHtml { frontends ...@@ -133,18 +122,19 @@ toHtml { frontends
newAsyncTasks = A.filter (\(GT.AsyncTaskWithType {task: GT.AsyncTask {id: id''}}) -> id' /= id'') asyncTasks newAsyncTasks = A.filter (\(GT.AsyncTaskWithType {task: GT.AsyncTask {id: id''}}) -> id' /= id'') asyncTasks
childNodes :: Session type ChildNodesProps =
-> Frontends (
-> R.State Reload children :: Array FTree
-> R.State Boolean , folderOpen :: R.State Boolean
-> Maybe AppRoute | CommonProps
-> R.State OpenNodes )
-> Array FTree
-> Array R.Element
childNodes _ _ _ _ _ _ [] = [] childNodes :: Record ChildNodesProps -> Array R.Element
childNodes _ _ _ (false /\ _) _ _ _ = [] childNodes { children: [] } = []
childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary = childNodes { folderOpen: (false /\ _) } = []
map (\ctree -> childNode {tree: ctree, asyncTasks: []}) $ sorted ary childNodes { children, folderOpen: (true /\ _), frontends, mCurrentRoute, openNodes, reload, session } =
map (\ctree -> childNode {tree: ctree, asyncTasks: []}) $ sorted children
where where
sorted :: Array FTree -> Array FTree sorted :: Array FTree -> Array FTree
sorted = A.sortWith (\(NTree (LNode {id}) _) -> id) sorted = A.sortWith (\(NTree (LNode {id}) _) -> id)
...@@ -156,7 +146,7 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary = ...@@ -156,7 +146,7 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary =
pure $ toHtml { frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } pure $ toHtml { frontends, mCurrentRoute, openNodes, reload, session, tasks, tree }
performAction :: { openNodes :: R.State OpenNodes performAction :: { openNodes :: R.State OpenNodes
, reload :: R.State Int , reload :: R.State Reload
, session :: Session , session :: Session
, tasks :: R.State (Array GT.AsyncTaskWithType) , tasks :: R.State (Array GT.AsyncTaskWithType)
, tree :: FTree } , tree :: FTree }
......
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