Commit 23ee97c0 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[TREE] corpus is selected now from the current route

parent cf6d459c
...@@ -18,12 +18,6 @@ import Effect.Aff (Aff, runAff) ...@@ -18,12 +18,6 @@ import Effect.Aff (Aff, runAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..)) import FFI.Simple ((..))
import Gargantext.Components.Loader2 (useLoader)
import Gargantext.Config (toUrl, End(..), NodeType(..), readNodeType)
import Gargantext.Config.REST (get, put, post, postWwwUrlencoded, delete)
import Gargantext.Types (class ToQuery, toQuery)
import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2
import Partial.Unsafe (unsafePartial) import Partial.Unsafe (unsafePartial)
import React (ReactClass, ReactElement) import React (ReactClass, ReactElement)
import React as React import React as React
...@@ -40,12 +34,20 @@ import Web.File.File (toBlob) ...@@ -40,12 +34,20 @@ import Web.File.File (toBlob)
import Web.File.FileList (FileList, item) import Web.File.FileList (FileList, item)
import Web.File.FileReader.Aff (readAsText) import Web.File.FileReader.Aff (readAsText)
import Gargantext.Components.Loader2 (useLoader)
import Gargantext.Config (toUrl, End(..), NodeType(..), readNodeType)
import Gargantext.Config.REST (get, put, post, postWwwUrlencoded, delete)
import Gargantext.Router as Router
import Gargantext.Types (class ToQuery, toQuery)
import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2
type Name = String type Name = String
type Open = Boolean type Open = Boolean
type URL = String type URL = String
type ID = Int type ID = Int
type Props = { root :: ID } type Props = { root :: ID, mCurrentRoute :: Maybe Router.Routes }
data NTree a = NTree a (Array (NTree a)) data NTree a = NTree a (Array (NTree a))
...@@ -185,7 +187,14 @@ nodeOptionsRename d activated id = case activated of ...@@ -185,7 +187,14 @@ nodeOptionsRename d activated id = case activated of
] ]
false -> [] false -> []
type TreeViewProps = { tree :: FTree } type TreeViewProps = { tree :: FTree, mCurrentRoute :: Maybe Router.Routes }
mCorpusId :: Maybe Router.Routes -> Maybe Int
mCorpusId (Just (Router.Corpus id)) = Just id
mCorpusId (Just (Router.CorpusDocument id _ _)) = Just id
mCorpusId _ = Nothing
loadedTreeview :: Spec State TreeViewProps Action loadedTreeview :: Spec State TreeViewProps Action
loadedTreeview = simpleSpec performAction render loadedTreeview = simpleSpec performAction render
...@@ -198,8 +207,10 @@ loadedTreeview = simpleSpec performAction render ...@@ -198,8 +207,10 @@ loadedTreeview = simpleSpec performAction render
] ]
] ]
treeViewClass :: ReactClass { tree :: FTree, children :: React.Children } treeViewClass :: ReactClass { tree :: FTree, mCurrentRoute :: Maybe Router.Routes, children :: React.Children }
treeViewClass = createClass "TreeView" loadedTreeview (\{tree} -> {state: tree, currentNode: Nothing}) treeViewClass = createClass "TreeView" loadedTreeview cpt
where
cpt {tree, mCurrentRoute} = {state: tree, currentNode: mCorpusId mCurrentRoute}
-- loadedTreeView p = R.createElement el p [] -- loadedTreeView p = R.createElement el p []
-- where -- where
...@@ -217,9 +228,9 @@ treeview = simpleSpec defaultPerformAction render ...@@ -217,9 +228,9 @@ treeview = simpleSpec defaultPerformAction render
render _ props _ _ = [R2.scuff $ R.createElement cpt props []] render _ props _ _ = [R2.scuff $ R.createElement cpt props []]
cpt = cpt =
R.hooksComponent "TreeView" \{root} _children -> R.hooksComponent "TreeView" \{root, mCurrentRoute} _children ->
useLoader root loadNode \currentPath loaded -> useLoader root loadNode \currentPath loaded ->
R2.buff $ React.createElement treeViewClass {tree: loaded} [] R2.buff $ React.createElement treeViewClass {tree: loaded, mCurrentRoute} []
--R2.scuff $ loadedTreeView {tree: loaded} --R2.scuff $ loadedTreeView {tree: loaded}
......
...@@ -419,7 +419,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -419,7 +419,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
Nothing -> Nothing ->
simpleSpec defaultPerformAction defaultRender simpleSpec defaultPerformAction defaultRender
Just treeId -> Just treeId ->
(cmapProps (const {root: treeId}) (noState Tree.treeview)) (cmapProps (const {root: treeId, mCurrentRoute: Nothing}) (noState Tree.treeview))
render' :: Render State {} Action render' :: Render State {} Action
......
...@@ -90,7 +90,7 @@ layout0 layout = ...@@ -90,7 +90,7 @@ layout0 layout =
withState \st -> withState \st ->
case st.loginState.authData of case st.loginState.authData of
Just (AuthData {tree_id}) -> Just (AuthData {tree_id}) ->
ls $ cmapProps (const {root: tree_id}) as ls $ cmapProps (const {root: tree_id, mCurrentRoute: st.currentRoute}) as
Nothing -> Nothing ->
outerLayout1 outerLayout1
, rs bs , rs bs
...@@ -138,7 +138,7 @@ layout1 layout = ...@@ -138,7 +138,7 @@ layout1 layout =
[ withState \st -> [ withState \st ->
case st.loginState.authData of case st.loginState.authData of
Just (AuthData {tree_id}) -> Just (AuthData {tree_id}) ->
ls $ cmapProps (const {root: tree_id}) as ls $ cmapProps (const {root: tree_id, mCurrentRoute: st.currentRoute}) as
Nothing -> Nothing ->
outerLayout1 outerLayout1
, rs bs , rs bs
......
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