Commit 9b7d6db6 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT] performAction parameters clearer + code alignment

parent 8b8e6345
......@@ -33,27 +33,45 @@ forestCpt :: R.Component Props
forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where
cpt { frontends, reload: extReload, route, sessions, showLogin } _ = do
-- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
asyncTasks <- R2.useLocalStorageState GAT.localStorageKey GAT.empty
R2.useCache
(frontends /\ route /\ sessions /\ fst openNodes /\ fst extReload /\ fst reload /\ fst asyncTasks)
( frontends
/\ route
/\ sessions
/\ fst openNodes
/\ fst extReload
/\ fst reload
/\ fst asyncTasks
)
(cpt' openNodes asyncTasks reload showLogin)
cpt' openNodes asyncTasks reload showLogin (frontends /\ route /\ sessions /\ _ /\ _ /\ _ /\ _) = do
pure $ R.fragment $ A.cons (plus showLogin) trees
where
trees = tree <$> unSessions sessions
tree s@(Session {treeId}) =
treeView { root: treeId, asyncTasks, frontends, mCurrentRoute: Just route, session: s, openNodes, reload }
treeView { root: treeId
, asyncTasks
, frontends
, mCurrentRoute: Just route
, session: s
, openNodes
, reload
}
plus :: R2.Setter Boolean -> R.Element
plus showLogin =
H.button {on: {click}, className: "btn btn-primary"}
[ H.div { "type": "", className: "fa fa-universal-access fa-lg"} [H.text " Log "]
, H.div {} [H.text " "]
H.button { on: {click}
, className: "btn btn-primary"
}
[ H.div { "type": ""
, className: "fa fa-universal-access fa-lg"
} [H.text " Log "]
, H.div {} [H.text " "]
--, H.div { "type": "", className: "fa fa-plus-circle fa-lg"} []
--, H.div { "type": "", className: "fa fa-minus-circle fa-lg"} []
]
]
-- TODO same as the one in the Login Modal (same CSS)
-- [ H.i { className: "material-icons md-36"} [] ]
where
......
......@@ -30,7 +30,6 @@ import Record as Record
import Record.Extra as RecordE
------------------------------------------------------------------------
type CommonProps =
( frontends :: Frontends
, mCurrentRoute :: Maybe AppRoute
......@@ -63,8 +62,7 @@ treeLoadView p = R.createElement treeLoadViewCpt p []
where
cpt { root, asyncTasks, mCurrentRoute, session, frontends, openNodes, reload } _children = do
let fetch _ = loadNode session root
let paint loaded = loadedTreeView {
asyncTasks
let paint loaded = loadedTreeView { asyncTasks
, frontends
, mCurrentRoute
, openNodes
......@@ -112,7 +110,7 @@ toHtml p@{ asyncTasks
where
el = R.hooksComponent "NodeView" cpt
commonProps = RecordE.pick p :: Record CommonProps
pAction = performAction (RecordE.pick p :: Record PerformActionProps)
pAction a = performAction a (RecordE.pick p :: Record PerformActionProps)
cpt _ _ = do
let nodeId = mkNodeId session id
......@@ -173,58 +171,73 @@ type PerformActionProps =
, tree :: FTree
)
performAction :: Record PerformActionProps
-> Action
performAction :: Action
-> Record PerformActionProps
-> Aff Unit
performAction p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } DeleteNode = do
void $ deleteNode session id
liftEffect do
setOpenNodes (Set.delete (mkNodeId session id))
performAction p RefreshTree
performAction { reload: (_ /\ setReload)
, session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _) } (DoSearch task) = do
liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] DoSearch task:" task
performAction { reload: (_ /\ setReload)
, session
, tasks: {onTaskAdd}
, tree: (NTree (LNode {id}) _) } (UpdateNode task) = do
liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] UpdateNode task:" task
performAction p@{ reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } (RenameNode name) = do
void $ rename session id $ RenameValue {text:name}
performAction p RefreshTree
performAction p@{ reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } (ShareNode username) = do
void $ share session id $ ShareValue {text:username}
performAction p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } (AddNode name nodeType) = do
task <- addNode session id $ AddNodeValue {name, nodeType}
liftEffect do
setOpenNodes (Set.insert (mkNodeId session id))
performAction p RefreshTree
performAction { session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _) } (UploadFile nodeType fileType mName contents) = do
task <- uploadFile session nodeType id fileType {mName, contents}
liftEffect $ onTaskAdd task
liftEffect $ log2 "uploaded, task:" task
performAction { reload: (_ /\ setReload) } RefreshTree = do
performAction DeleteNode p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _)
} =
do
void $ deleteNode session id
liftEffect do
setOpenNodes (Set.delete (mkNodeId session id))
performAction RefreshTree p
performAction (DoSearch task) { reload: (_ /\ setReload)
, session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _)
} =
do
liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] DoSearch task:" task
performAction (UpdateNode task) { reload: (_ /\ setReload)
, session
, tasks: {onTaskAdd}
, tree: (NTree (LNode {id}) _)
} =
do
liftEffect $ onTaskAdd task
liftEffect $ log2 "[performAction] UpdateNode task:" task
performAction (RenameNode name) p@{ reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _)
}
=
do
void $ rename session id $ RenameValue {text:name}
performAction RefreshTree p
performAction (ShareNode username) p@{ reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _)
} =
do
void $ share session id $ ShareValue {text:username}
performAction (AddNode name nodeType) p@{ openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _)
} =
do
task <- addNode session id $ AddNodeValue {name, nodeType}
liftEffect do
setOpenNodes (Set.insert (mkNodeId session id))
performAction RefreshTree p
performAction (UploadFile nodeType fileType mName contents) { session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _)
} =
do
task <- uploadFile session nodeType id fileType {mName, contents}
liftEffect $ onTaskAdd task
liftEffect $ log2 "uploaded, task:" task
performAction RefreshTree { reload: (_ /\ setReload) } = do
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