Commit 90b71a3e authored by Alexandre Delanoë's avatar Alexandre Delanoë

[CODE DESIGN]

parent 208160f3
...@@ -50,9 +50,23 @@ treeView props = R.createElement treeViewCpt props [] ...@@ -50,9 +50,23 @@ treeView props = R.createElement treeViewCpt props []
treeViewCpt :: R.Component Props treeViewCpt :: R.Component Props
treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt
where where
cpt { root, mCurrentRoute, session, frontends, openNodes, reload, asyncTasks} _children = do cpt { root
pure $ treeLoadView , mCurrentRoute
{ root, mCurrentRoute, session, frontends, openNodes, reload, asyncTasks} , session
, frontends
, openNodes
, reload
, asyncTasks
} _children = do
pure $ treeLoadView { root
, mCurrentRoute
, session
, frontends
, openNodes
, reload
, asyncTasks
}
treeLoadView :: Record Props -> R.Element treeLoadView :: Record Props -> R.Element
treeLoadView p = R.createElement treeLoadViewCpt p [] treeLoadView p = R.createElement treeLoadViewCpt p []
...@@ -60,7 +74,14 @@ treeLoadView p = R.createElement treeLoadViewCpt p [] ...@@ -60,7 +74,14 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
treeLoadViewCpt :: R.Component Props treeLoadViewCpt :: R.Component Props
treeLoadViewCpt = R.hooksComponent "TreeLoadView" cpt treeLoadViewCpt = R.hooksComponent "TreeLoadView" cpt
where where
cpt { root, asyncTasks, mCurrentRoute, session, frontends, openNodes, reload } _children = do cpt { root
, asyncTasks
, mCurrentRoute
, session
, frontends
, openNodes
, reload
} _children = do
let fetch _ = loadNode session root let fetch _ = loadNode session root
let paint loaded = loadedTreeView { asyncTasks let paint loaded = loadedTreeView { asyncTasks
, frontends , frontends
...@@ -85,9 +106,25 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p [] ...@@ -85,9 +106,25 @@ loadedTreeView p = R.createElement loadedTreeViewCpt p []
loadedTreeViewCpt :: R.Component TreeViewProps loadedTreeViewCpt :: R.Component TreeViewProps
loadedTreeViewCpt = R.hooksComponent "LoadedTreeView" cpt loadedTreeViewCpt = R.hooksComponent "LoadedTreeView" cpt
where where
cpt { asyncTasks, frontends, mCurrentRoute, openNodes, reload, tasks, tree, session } _ = do cpt { asyncTasks
pure $ H.div {className: "tree"} , frontends
[ toHtml { asyncTasks, frontends, mCurrentRoute, openNodes, reload, session, tasks, tree } ] , mCurrentRoute
, openNodes
, reload
, tasks
, tree
, session
} _ = pure $ H.div { className: "tree"}
[ toHtml { asyncTasks
, frontends
, mCurrentRoute
, openNodes
, reload
, session
, tasks
, tree
}
]
------------------------------------------------------------------------ ------------------------------------------------------------------------
type ToHtmlProps = type ToHtmlProps =
...@@ -105,40 +142,50 @@ toHtml p@{ asyncTasks ...@@ -105,40 +142,50 @@ toHtml p@{ asyncTasks
, openNodes , openNodes
, reload: reload@(_ /\ setReload) , reload: reload@(_ /\ setReload)
, session , session
, tasks: tasks@{ onTaskAdd, onTaskFinish, tasks: tasks' } , tasks: tasks@{ onTaskAdd
, tree: tree@(NTree (LNode {id, name, nodeType}) ary) } = R.createElement el {} [] , onTaskFinish
where , tasks: tasks'
el = R.hooksComponent "NodeView" cpt }
commonProps = RecordE.pick p :: Record CommonProps , tree: tree@(NTree (LNode { id
pAction a = performAction a (RecordE.pick p :: Record PerformActionProps) , name
, nodeType
cpt _ _ = do }
let nodeId = mkNodeId session id ) ary
let folderIsOpen = Set.member nodeId (fst openNodes) )
let setFn = if folderIsOpen then Set.delete else Set.insert } =
let toggleFolderIsOpen _ = (snd openNodes) (setFn nodeId) R.createElement el {} []
let folderOpen = Tuple folderIsOpen toggleFolderIsOpen where
el = R.hooksComponent "NodeView" cpt
let withId (NTree (LNode {id: id'}) _) = id' commonProps = RecordE.pick p :: Record CommonProps
pAction a = performAction a (RecordE.pick p :: Record PerformActionProps)
pure $ H.ul {}
[ H.li {} cpt _ _ = do
( [ nodeMainSpan { id let nodeId = mkNodeId session id
, dispatch: pAction let folderIsOpen = Set.member nodeId (fst openNodes)
, folderOpen let setFn = if folderIsOpen then Set.delete else Set.insert
, frontends let toggleFolderIsOpen _ = (snd openNodes) (setFn nodeId)
, mCurrentRoute let folderOpen = Tuple folderIsOpen toggleFolderIsOpen
, name
, nodeType let withId (NTree (LNode {id: id'}) _) = id'
, session
, tasks pure $ H.ul {}
} ] [ H.li {}
<> childNodes (Record.merge commonProps ( [ nodeMainSpan { id
{ asyncTasks , dispatch: pAction
, children: ary , folderOpen
, folderOpen }) , frontends
) , mCurrentRoute
] , name
, nodeType
, session
, tasks
} ]
<> childNodes (Record.merge commonProps
{ asyncTasks
, children: ary
, folderOpen })
)
]
type ChildNodesProps = type ChildNodesProps =
...@@ -153,11 +200,12 @@ childNodes { children: [] } = [] ...@@ -153,11 +200,12 @@ childNodes { children: [] } = []
childNodes { folderOpen: (false /\ _) } = [] childNodes { folderOpen: (false /\ _) } = []
childNodes props@{ asyncTasks, children, reload } = childNodes props@{ asyncTasks, children, reload } =
map (\ctree@(NTree (LNode {id}) _) -> map (\ctree@(NTree (LNode {id}) _) ->
toHtml (Record.merge commonProps { toHtml (Record.merge commonProps { asyncTasks
asyncTasks , tasks: tasksStruct id asyncTasks reload
, tasks: tasksStruct id asyncTasks reload , tree: ctree
, tree: ctree }
})) $ sorted children )
) $ sorted children
where where
commonProps = RecordE.pick props :: Record CommonProps commonProps = RecordE.pick props :: Record CommonProps
sorted :: Array FTree -> Array FTree sorted :: Array FTree -> Array FTree
...@@ -171,6 +219,7 @@ type PerformActionProps = ...@@ -171,6 +219,7 @@ type PerformActionProps =
, tree :: FTree , tree :: FTree
) )
-------
performAction :: Action performAction :: Action
-> Record PerformActionProps -> Record PerformActionProps
-> Aff Unit -> Aff Unit
...@@ -185,6 +234,8 @@ performAction DeleteNode p@{ openNodes: (_ /\ setOpenNodes) ...@@ -185,6 +234,8 @@ performAction DeleteNode p@{ openNodes: (_ /\ setOpenNodes)
setOpenNodes (Set.delete (mkNodeId session id)) setOpenNodes (Set.delete (mkNodeId session id))
performAction RefreshTree p performAction RefreshTree p
-------
performAction (DoSearch task) { reload: (_ /\ setReload) performAction (DoSearch task) { reload: (_ /\ setReload)
, session , session
, tasks: { onTaskAdd } , tasks: { onTaskAdd }
...@@ -194,6 +245,8 @@ performAction (DoSearch task) { reload: (_ /\ setReload) ...@@ -194,6 +245,8 @@ performAction (DoSearch task) { reload: (_ /\ setReload)
liftEffect $ onTaskAdd task liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] DoSearch task:" task liftEffect $ log2 "[performAction] DoSearch task:" task
-------
performAction (UpdateNode task) { reload: (_ /\ setReload) performAction (UpdateNode task) { reload: (_ /\ setReload)
, session , session
, tasks: {onTaskAdd} , tasks: {onTaskAdd}
...@@ -203,6 +256,8 @@ performAction (UpdateNode task) { reload: (_ /\ setReload) ...@@ -203,6 +256,8 @@ performAction (UpdateNode task) { reload: (_ /\ setReload)
liftEffect $ onTaskAdd task liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] UpdateNode task:" task liftEffect $ log2 "[performAction] UpdateNode task:" task
-------
performAction (RenameNode name) p@{ reload: (_ /\ setReload) performAction (RenameNode name) p@{ reload: (_ /\ setReload)
, session , session
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
...@@ -211,6 +266,8 @@ performAction (RenameNode name) p@{ reload: (_ /\ setReload) ...@@ -211,6 +266,8 @@ performAction (RenameNode name) p@{ reload: (_ /\ setReload)
void $ rename session id $ RenameValue {text:name} void $ rename session id $ RenameValue {text:name}
performAction RefreshTree p performAction RefreshTree p
-------
performAction (ShareNode username) p@{ reload: (_ /\ setReload) performAction (ShareNode username) p@{ reload: (_ /\ setReload)
, session , session
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
...@@ -218,6 +275,8 @@ performAction (ShareNode username) p@{ reload: (_ /\ setReload) ...@@ -218,6 +275,8 @@ performAction (ShareNode username) p@{ reload: (_ /\ setReload)
do do
void $ share session id $ ShareValue {text:username} void $ share session id $ ShareValue {text:username}
-------
performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes) performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload) , reload: (_ /\ setReload)
, session , session
...@@ -229,6 +288,7 @@ performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes) ...@@ -229,6 +288,7 @@ performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes)
setOpenNodes (Set.insert (mkNodeId session id)) setOpenNodes (Set.insert (mkNodeId session id))
performAction RefreshTree p performAction RefreshTree p
-------
performAction (UploadFile nodeType fileType mName contents) { session performAction (UploadFile nodeType fileType mName contents) { session
, tasks: { onTaskAdd } , tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
...@@ -238,5 +298,7 @@ performAction (UploadFile nodeType fileType mName contents) { session ...@@ -238,5 +298,7 @@ performAction (UploadFile nodeType fileType mName contents) { session
liftEffect $ onTaskAdd task liftEffect $ onTaskAdd task
liftEffect $ log2 "uploaded, task:" task liftEffect $ log2 "uploaded, task:" task
-------
performAction RefreshTree { reload: (_ /\ setReload) } = do performAction RefreshTree { reload: (_ /\ setReload) } = do
liftEffect $ setReload (_ + 1) liftEffect $ setReload (_ + 1)
-------
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