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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
1c331ace
Commit
1c331ace
authored
Jul 08, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TREE] mCurrentNode as global state
This prevents duplicate selected nodes to be made/shown.
parent
5735f12b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
Tree.purs
src/Gargantext/Components/Tree.purs
+22
-21
No files found.
src/Gargantext/Components/Tree.purs
View file @
1c331ace
...
@@ -119,7 +119,7 @@ data Action = Submit String
...
@@ -119,7 +119,7 @@ data Action = Submit String
type State = { tree :: FTree
type State = { tree :: FTree
, mCurrentNode :: Maybe ID
--
, mCurrentNode :: Maybe ID
}
}
mapFTree :: (FTree -> FTree) -> State -> State
mapFTree :: (FTree -> FTree) -> State -> State
...
@@ -128,29 +128,29 @@ mapFTree f s@{tree} = s {tree = f tree}
...
@@ -128,29 +128,29 @@ mapFTree f s@{tree} = s {tree = f tree}
-- TODO: make it a local function
-- TODO: make it a local function
--performAction :: forall props. PerformAction State props Action
--performAction :: forall props. PerformAction State props Action
performAction :: R.State Int -> R.State State -> Action -> Aff Unit
performAction :: R.State Int -> R.State State ->
R.State (Maybe ID) ->
Action -> Aff Unit
performAction (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setState) DeleteNode = do
performAction (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setState)
_
DeleteNode = do
void $ deleteNode id
void $ deleteNode id
--modifyState_ $ mapFTree $ filterNTree (\(LNode {id}) -> id /= nid)
--modifyState_ $ mapFTree $ filterNTree (\(LNode {id}) -> id /= nid)
--liftEffect $ setState $ mapFTree $ filterNTree $ \(LNode {id: nid}) -> nid /= id
--liftEffect $ setState $ mapFTree $ filterNTree $ \(LNode {id: nid}) -> nid /= id
liftEffect $ setReload $ \r -> r + 1
liftEffect $ setReload $ \r -> r + 1
performAction _ ({tree: NTree (LNode {id}) _} /\ setState) (Submit name) = do
performAction _ ({tree: NTree (LNode {id}) _} /\ setState)
_
(Submit name) = do
void $ renameNode id $ RenameValue {name}
void $ renameNode id $ RenameValue {name}
--modifyState_ $ mapFTree $ setNodeName rid name
--modifyState_ $ mapFTree $ setNodeName rid name
liftEffect $ setState $ \s@{tree: NTree (LNode node) arr} -> s {tree = NTree (LNode node {name = name}) arr}
liftEffect $ setState $ \s@{tree: NTree (LNode node) arr} -> s {tree = NTree (LNode node {name = name}) arr}
performAction (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setState) (CreateSubmit name nodeType) = do
performAction (_ /\ setReload) (s@{tree: NTree (LNode {id}) _} /\ setState)
_
(CreateSubmit name nodeType) = do
void $ createNode id $ CreateValue {name, nodeType}
void $ createNode id $ CreateValue {name, nodeType}
--modifyState_ $ mapFTree $ map $ hidePopOverNode nid
--modifyState_ $ mapFTree $ map $ hidePopOverNode nid
liftEffect $ setReload $ \r -> r + 1
liftEffect $ setReload $ \r -> r + 1
performAction _ ({tree: NTree (LNode {id}) _} /\
setStat
e) CurrentNode =
performAction _ ({tree: NTree (LNode {id}) _} /\
_) (_ /\ setMCurrentNod
e) CurrentNode =
--modifyState_ $ \{state: s} -> {state: s, mCurrentNode : Just nid}
--modifyState_ $ \{state: s} -> {state: s, mCurrentNode : Just nid}
liftEffect $ set
State $ \s -> s {mCurrentNode = Just id}
liftEffect $ set
MCurrentNode $ const $ Just id
performAction _ ({tree: NTree (LNode {id}) _} /\ _) (UploadFile fileType contents) = do
performAction _ ({tree: NTree (LNode {id}) _} /\ _)
_
(UploadFile fileType contents) = do
hashes <- uploadFile id fileType contents
hashes <- uploadFile id fileType contents
liftEffect $ log2 "uploaded:" hashes
liftEffect $ log2 "uploaded:" hashes
...
@@ -172,10 +172,11 @@ loadedTreeView setReload p = R.createElement el p []
...
@@ -172,10 +172,11 @@ loadedTreeView setReload p = R.createElement el p []
where
where
el = R.hooksComponent "LoadedTreeView" cpt
el = R.hooksComponent "LoadedTreeView" cpt
cpt {tree, mCurrentRoute} _ = do
cpt {tree, mCurrentRoute} _ = do
setState <- R.useState' {tree, mCurrentNode}
setMCurrentNode <- R.useState' mCurrentNode
setState <- R.useState' {tree}
pure $ H.div {className: "tree"}
pure $ H.div {className: "tree"}
[ toHtml setReload setState ]
[ toHtml setReload setState
setMCurrentNode
]
where
where
mCurrentNode = mCorpusId mCurrentRoute
mCurrentNode = mCorpusId mCurrentRoute
...
@@ -199,19 +200,19 @@ treeview = R2.elSpec $ R.hooksComponent "TreeView" cpt
...
@@ -199,19 +200,19 @@ treeview = R2.elSpec $ R.hooksComponent "TreeView" cpt
-- START toHtml
-- START toHtml
toHtml :: R.State Int -> R.State State -> R.Element
toHtml :: R.State Int -> R.State State -> R.
State (Maybe ID) -> R.
Element
--toHtml d s@(NTree (LNode {id, name, nodeType}) ary) n = R.createElement el {} []
--toHtml d s@(NTree (LNode {id, name, nodeType}) ary) n = R.createElement el {} []
toHtml setReload setState@({tree: (NTree (LNode {id, name, nodeType}) ary)
, mCurrentNode}
/\ _) = R.createElement el {} []
toHtml setReload setState@({tree: (NTree (LNode {id, name, nodeType}) ary)
} /\ _) setMCurrentNode@(mCurrentNode
/\ _) = R.createElement el {} []
where
where
el = R.hooksComponent "NodeView" cpt
el = R.hooksComponent "NodeView" cpt
pAction = performAction setReload setState
pAction = performAction setReload setState
setMCurrentNode
cpt props _ = do
cpt props _ = do
folderOpen <- R.useState' true
folderOpen <- R.useState' true
pure $ H.ul {}
pure $ H.ul {}
[ H.li {}
[ H.li {}
( [ nodeMainSpan pAction {id, name, nodeType, mCurrentNode} folderOpen ]
( [ nodeMainSpan pAction {id, name, nodeType, mCurrentNode} folderOpen ]
<> childNodes setReload
mCurrentNode ary folderOpen
<> childNodes setReload
setMCurrentNode folderOpen ary
)
)
]
]
...
@@ -289,18 +290,18 @@ fldr :: Boolean -> String
...
@@ -289,18 +290,18 @@ fldr :: Boolean -> String
fldr open = if open then "glyphicon glyphicon-folder-open" else "glyphicon glyphicon-folder-close"
fldr open = if open then "glyphicon glyphicon-folder-open" else "glyphicon glyphicon-folder-close"
childNodes :: R.State Int ->
Maybe ID -> Array FTree -> R.State Boolean
-> Array R.Element
childNodes :: R.State Int ->
R.State (Maybe ID) -> R.State Boolean -> Array FTree
-> Array R.Element
childNodes _ _
[] _
= []
childNodes _ _
_ []
= []
childNodes _ _
_ (false /\ _)
= []
childNodes _ _
(false /\ _) _
= []
childNodes setReload
mCurrentNode ary (true /\ _) = map (\ctree -> childNode {tree: ctree, mCurrentNod
e}) ary
childNodes setReload
setMCurrentNode (true /\ _) ary = map (\ctree -> childNode {tree: ctre
e}) ary
where
where
childNode :: State -> R.Element
childNode :: State -> R.Element
childNode props = R.createElement el props []
childNode props = R.createElement el props []
el = R.hooksComponent "ChildNodeView" cpt
el = R.hooksComponent "ChildNodeView" cpt
cpt {tree
, mCurrentNode
} _ = do
cpt {tree} _ = do
setState <- R.useState' {tree
, mCurrentNode
}
setState <- R.useState' {tree}
pure $ toHtml setReload setState
pure $ toHtml setReload setState
setMCurrentNode
-- END toHtml
-- END toHtml
...
...
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