Commit 9930c4f4 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[tree] better typing of performAction

parent 716f3342
...@@ -91,7 +91,7 @@ toHtml :: R.State Reload ...@@ -91,7 +91,7 @@ toHtml :: R.State Reload
toHtml reload@(_ /\ setReload) tree@(NTree (LNode {id, name, nodeType}) ary) tasks@(asyncTasks /\ setAsyncTasks) session frontends mCurrentRoute openNodes = R.createElement el {} [] toHtml reload@(_ /\ setReload) tree@(NTree (LNode {id, name, nodeType}) ary) tasks@(asyncTasks /\ setAsyncTasks) session frontends mCurrentRoute openNodes = R.createElement el {} []
where where
el = R.hooksComponent "NodeView" cpt el = R.hooksComponent "NodeView" cpt
pAction = performAction session tree reload openNodes tasks pAction = performAction {openNodes, reload, session, tasks, tree}
cpt props _ = do cpt props _ = do
let nodeId = mkNodeId session id let nodeId = mkNodeId session id
...@@ -144,36 +144,49 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary = ...@@ -144,36 +144,49 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary =
tasks <- R.useState' asyncTasks tasks <- R.useState' asyncTasks
pure $ toHtml reload tree tasks session frontends mCurrentRoute openNodes pure $ toHtml reload tree tasks session frontends mCurrentRoute openNodes
performAction :: Session performAction :: { openNodes :: R.State OpenNodes
-> FTree , reload :: R.State Int
-> R.State Int , session :: Session
-> R.State OpenNodes , tasks :: R.State (Array GT.AsyncTaskWithType)
-> R.State (Array GT.AsyncTaskWithType) , tree :: FTree }
-> Action -> Action
-> Aff Unit -> Aff Unit
performAction session (NTree (LNode {id}) _) (_ /\ setReload) (_ /\ setOpenNodes) _ DeleteNode = do performAction { openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } DeleteNode = do
void $ deleteNode session id void $ deleteNode session id
liftEffect do liftEffect do
setOpenNodes (Set.delete (mkNodeId session id)) setOpenNodes (Set.delete (mkNodeId session id))
setReload (_ + 1) setReload (_ + 1)
performAction session (NTree (LNode {id}) _) (_ /\ setReload) _ (_ /\ setAsyncTasks) (SearchQuery task) = do performAction { reload: (_ /\ setReload)
, session
, tasks: (_ /\ setAsyncTasks)
, tree: (NTree (LNode {id}) _) } (SearchQuery task) = do
liftEffect $ setAsyncTasks $ A.cons task liftEffect $ setAsyncTasks $ A.cons task
liftEffect $ log2 "[performAction] SearchQuery task:" task liftEffect $ log2 "[performAction] SearchQuery task:" task
liftEffect $ setReload (_ + 1) liftEffect $ setReload (_ + 1)
performAction session (NTree (LNode {id}) _) (_ /\ setReload) _ _ (Submit name) = do performAction { reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } (Submit name) = do
void $ renameNode session id $ RenameValue {name} void $ renameNode session id $ RenameValue {name}
liftEffect do liftEffect do
setReload (_ + 1) setReload (_ + 1)
performAction session (NTree (LNode {id}) _) (_ /\ setReload) (_ /\ setOpenNodes) _ (CreateSubmit name nodeType) = do performAction { openNodes: (_ /\ setOpenNodes)
, reload: (_ /\ setReload)
, session
, tree: (NTree (LNode {id}) _) } (CreateSubmit name nodeType) = do
void $ createNode session id $ CreateValue {name, nodeType} void $ createNode session id $ CreateValue {name, nodeType}
liftEffect do liftEffect do
setOpenNodes (Set.insert (mkNodeId session id)) setOpenNodes (Set.insert (mkNodeId session id))
setReload (_ + 1) setReload (_ + 1)
performAction session (NTree (LNode {id}) _) _ _ (_ /\ setAsyncTasks) (UploadFile nodeType fileType mName contents) = do performAction { session
, tasks: (_ /\ setAsyncTasks)
, tree: (NTree (LNode {id}) _) } (UploadFile nodeType fileType mName contents) = do
task <- uploadFile session nodeType id fileType {mName, contents} task <- uploadFile session nodeType id fileType {mName, contents}
liftEffect $ setAsyncTasks $ A.cons task liftEffect $ setAsyncTasks $ A.cons task
liftEffect $ log2 "uploaded, task:" task liftEffect $ log2 "uploaded, task:" task
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