Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
14d096bb
Commit
14d096bb
authored
Jan 27, 2020
by
Justin Woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lift reloads to forest and update open nodes on delete and create
parent
99ca6f6e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
+23
-14
Forest.purs
src/Gargantext/Components/Forest.purs
+8
-3
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+15
-11
No files found.
src/Gargantext/Components/Forest.purs
View file @
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,14 +31,18 @@ forest props = R.createElement forestCpt props []
...
@@ -30,14 +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)
R2.useCache (frontends /\ route /\ sessions /\ fst openNodes) (cpt' openNodes showLogin)
R2.useCache
cpt' openNodes showLogin (frontends /\ route /\ sessions /\ openNodesState) = do
(frontends /\ route /\ sessions /\ fst openNodes /\ fst reload)
(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, frontends, mCurrentRoute: Just route, session: s, openNodes }
treeView { root: treeId, frontends, mCurrentRoute: Just route, session: s, openNodes
, reload
}
plus :: R2.Setter Boolean -> R.Element
plus :: R2.Setter Boolean -> R.Element
plus showLogin =
plus showLogin =
...
...
src/Gargantext/Components/Forest/Tree.purs
View file @
14d096bb
...
@@ -29,6 +29,7 @@ type Props = ( root :: ID
...
@@ -29,6 +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 Reload
)
)
treeView :: Record Props -> R.Element
treeView :: Record Props -> R.Element
...
@@ -37,9 +38,7 @@ treeView props = R.createElement treeViewCpt props []
...
@@ -37,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 }
...
@@ -93,7 +92,7 @@ toHtml :: R.State Reload
...
@@ -93,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)
...
@@ -145,22 +144,27 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary =
...
@@ -145,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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment