Commit 4c9ce917 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] conflicts on merge

parents 2c5f796d 14d096bb
...@@ -9,6 +9,7 @@ import Data.Set as Set ...@@ -9,6 +9,7 @@ import Data.Set as Set
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Gargantext.Components.Forest.Tree (treeView) import Gargantext.Components.Forest.Tree (treeView)
import Gargantext.Components.Forest.Tree.Node.Action (Reload)
import Gargantext.Components.Login.Types (TreeId) import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Routes (AppRoute) import Gargantext.Routes (AppRoute)
...@@ -30,21 +31,18 @@ forest props = R.createElement forestCpt props [] ...@@ -30,21 +31,18 @@ forest props = R.createElement forestCpt props []
forestCpt :: R.Component Props forestCpt :: R.Component Props
forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where
cpt {frontends, route, sessions, showLogin } _ = do cpt {frontends, 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 :: Set TreeId) openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: Set TreeId)
reload <- R.useState' (0 :: Int) R2.useCache
R2.useCache (frontends /\ route /\ sessions /\ fst openNodes) (cpt' reload openNodes showLogin) (frontends /\ route /\ sessions /\ fst openNodes /\ fst reload)
cpt' reload openNodes showLogin (frontends /\ route /\ sessions /\ openNodesState) = do (cpt' openNodes reload showLogin)
cpt' openNodes reload showLogin (frontends /\ route /\ sessions /\ _ /\ _) = do
pure $ R.fragment $ A.cons (plus showLogin) trees pure $ R.fragment $ A.cons (plus showLogin) trees
where where
trees = tree <$> unSessions sessions trees = tree <$> unSessions sessions
tree s@(Session {treeId}) = tree s@(Session {treeId}) =
treeView { root: treeId treeView { root: treeId, frontends, mCurrentRoute: Just route, session: s, openNodes, reload }
, frontends
, mCurrentRoute: Just route
, session: s
, openNodes
, reload
}
plus :: R2.Setter Boolean -> R.Element plus :: R2.Setter Boolean -> R.Element
plus showLogin = plus showLogin =
......
...@@ -29,7 +29,7 @@ type Props = ( root :: ID ...@@ -29,7 +29,7 @@ type Props = ( root :: ID
, session :: Session , session :: Session
, frontends :: Frontends , frontends :: Frontends
, openNodes :: R.State (Set TreeId) , openNodes :: R.State (Set TreeId)
, reload :: R.State Int , reload :: R.State Reload
) )
treeView :: Record Props -> R.Element treeView :: Record Props -> R.Element
...@@ -38,9 +38,7 @@ treeView props = R.createElement treeViewCpt props [] ...@@ -38,9 +38,7 @@ 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 } _children = do cpt { root, mCurrentRoute, session, frontends, openNodes, reload } _children = do
-- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload)
pure $ treeLoadView pure $ treeLoadView
{ root, mCurrentRoute, session, frontends, openNodes, reload } { root, mCurrentRoute, session, frontends, openNodes, reload }
...@@ -67,7 +65,7 @@ type TreeViewProps = ( tree :: FTree ...@@ -67,7 +65,7 @@ type TreeViewProps = ( tree :: FTree
, frontends :: Frontends , frontends :: Frontends
, session :: Session , session :: Session
, openNodes :: R.State (Set TreeId) , openNodes :: R.State (Set TreeId)
, reload :: R.State Reload , reload :: R.State Reload
) )
...@@ -94,7 +92,7 @@ toHtml :: R.State Reload ...@@ -94,7 +92,7 @@ toHtml :: R.State Reload
toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asyncTasks} /\ setTreeState) session frontends mCurrentRoute openNodes = R.createElement el {} [] toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asyncTasks} /\ setTreeState) session frontends mCurrentRoute openNodes = R.createElement el {} []
where where
el = R.hooksComponent "NodeView" cpt el = R.hooksComponent "NodeView" cpt
pAction = performAction session reload treeState pAction = performAction session reload openNodes treeState
cpt props _ = do cpt props _ = do
let folderIsOpen = Set.member id (fst openNodes) let folderIsOpen = Set.member id (fst openNodes)
...@@ -146,22 +144,27 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary = ...@@ -146,22 +144,27 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary =
performAction :: Session performAction :: Session
-> R.State Int -> R.State Int
-> R.State (Set TreeId)
-> R.State Tree -> R.State Tree
-> Action -> Action
-> Aff Unit -> Aff Unit
performAction session (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setTree) DeleteNode = do performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) DeleteNode = do
void $ deleteNode session id void $ deleteNode session id
liftEffect $ setReload (_ + 1) liftEffect do
setOpenNodes (Set.delete id)
setReload (_ + 1)
performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name) = do performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name) = do
void $ renameNode session id $ RenameValue {name} void $ renameNode session id $ RenameValue {name}
liftEffect $ setTree $ \s@{tree: NTree (LNode node) arr} -> s {tree = NTree (LNode node {name = name}) arr} liftEffect $ setTree $ \s@{tree: NTree (LNode node) arr} -> s {tree = NTree (LNode node {name = name}) arr}
performAction session (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setTree) (CreateSubmit name nodeType) = do performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) (CreateSubmit name nodeType) = do
void $ createNode session id $ CreateValue {name, nodeType} void $ createNode session id $ CreateValue {name, nodeType}
liftEffect $ setReload (_ + 1) liftEffect do
setOpenNodes (Set.insert id)
setReload (_ + 1)
performAction session _ ({tree: NTree (LNode {id}) _} /\ setTree) (UploadFile fileType contents) = do performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (UploadFile fileType contents) = do
task <- uploadFile session id fileType contents task <- uploadFile session id fileType contents
liftEffect $ setTree $ \t@{asyncTasks} -> t { asyncTasks = A.cons task asyncTasks } liftEffect $ setTree $ \t@{asyncTasks} -> t { asyncTasks = A.cons task asyncTasks }
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