Commit 6ff0feb6 authored by Fabien Manière's avatar Fabien Manière

when the tree is drawn, open the nodes from the breadcrumb trail, related to the current node

parent 6bc1e588
...@@ -8,7 +8,7 @@ import Data.Array as A ...@@ -8,7 +8,7 @@ import Data.Array as A
import Data.Int (fromString) import Data.Int (fromString)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.String (Pattern(..), split) import Data.String (Pattern(..), split)
import Gargantext.Components.App.Store (Boxes) import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb) import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb)
import Gargantext.Components.GraphQL.Tree (BreadcrumbInfo, TreeNode) import Gargantext.Components.GraphQL.Tree (BreadcrumbInfo, TreeNode)
...@@ -30,7 +30,7 @@ import Toestand as T ...@@ -30,7 +30,7 @@ import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Breadcrumb" here = R2.here "Gargantext.Components.Forest.Breadcrumb"
type PropsBoxes = ( boxes :: Boxes ) type PropsBoxes = ( boxes :: Store.Boxes )
type Props = type Props =
( nodeId :: Int ( nodeId :: Int
...@@ -232,10 +232,16 @@ breadcrumbItemCpt = here.component "breadcrumbItemCpt" cpt where ...@@ -232,10 +232,16 @@ breadcrumbItemCpt = here.component "breadcrumbItemCpt" cpt where
, format , format
} _ = do } _ = do
boxes@{ forestOpen } <- Store.use
url <- R.unsafeHooksEffect GU.href url <- R.unsafeHooksEffect GU.href
let sid = sessionId session let sid = sessionId session
let rootId = treeId session let rootId = treeId session
let currentNodeIdFromUrl = mkNodeId session linkId
R.unsafeHooksEffect $ T.modify_ (openNodesInsert (currentNodeIdFromUrl)) forestOpen
pure $ pure $
if format == "text" if format == "text"
......
...@@ -158,6 +158,7 @@ getNodeTreeFirstLevel session nodeId = get session $ GR.TreeFirstLevel (Just nod ...@@ -158,6 +158,7 @@ getNodeTreeFirstLevel session nodeId = get session $ GR.TreeFirstLevel (Just nod
tree :: R2.Leaf TreeProps tree :: R2.Leaf TreeProps
tree props = R.createElement treeCpt props [] tree props = R.createElement treeCpt props []
treeCpt :: R.Component TreeProps treeCpt :: R.Component TreeProps
treeCpt = here.component "tree" cpt where treeCpt = here.component "tree" cpt where
cpt p@{ frontends cpt p@{ frontends
...@@ -167,24 +168,16 @@ treeCpt = here.component "tree" cpt where ...@@ -167,24 +168,16 @@ treeCpt = here.component "tree" cpt where
, tree: NTree (LNode { id, name, nodeType }) children } _ = do , tree: NTree (LNode { id, name, nodeType }) children } _ = do
boxes@{ forestOpen } <- Store.use boxes@{ forestOpen } <- Store.use
url <- R.unsafeHooksEffect GU.href
let nodeIdFromUrl = fromMaybe 0 $ fromString $ getLastUrlElement url
let currentNodeIdFromUrl = mkNodeId session nodeIdFromUrl
-- R.unsafeHooksEffect $ Console.log $ "id: " <> show id
-- R.unsafeHooksEffect $ Console.log $ "nodeIdFromUrl: " <> show nodeIdFromUrl
-- R.unsafeHooksEffect $ Console.log $ "forestOpen avant modification: " <> show forestOpen
R.unsafeHooksEffect $ T.modify_ (openNodesInsert (currentNodeIdFromUrl)) forestOpen
-- R.unsafeHooksEffect $ T.modify_ (openNodesInsert (mkNodeId session 2)) forestOpen
-- folderOpen <- useOpenNodesMemberBox currentNodeIdFromUrl forestOpen
-- let currentNodeId = if id == nodeIdFromUrl then currentNodeIdFromUrl else nodeId
isBoxVisible <- T.useBox false isBoxVisible <- T.useBox false
folderOpen <- useOpenNodesMemberBox nodeId forestOpen folderOpen <- useOpenNodesMemberBox nodeId forestOpen
folderOpen' <- T.useLive T.unequal folderOpen folderOpen' <- T.useLive T.unequal folderOpen
R.useEffect' do
selectedLeaf <- R2.querySelector ".mainleaf--selected"
case selectedLeaf of
Nothing -> pure unit
Just el -> R2.scrollIntoView el
pure $ pure $
H.div H.div
......
...@@ -53,3 +53,8 @@ export function _keyCode(e) { ...@@ -53,3 +53,8 @@ export function _keyCode(e) {
// https://www.w3schools.com/jsref/event_key_keycode.asp // https://www.w3schools.com/jsref/event_key_keycode.asp
return e.which || e.keyCode; return e.which || e.keyCode;
} }
export function _scrollIntoView(el) {
return el.scrollIntoView();
}
\ No newline at end of file
...@@ -281,6 +281,11 @@ getElementById = (flip delay) h ...@@ -281,6 +281,11 @@ getElementById = (flip delay) h
where where
h id = pure $ toMaybe $ document ... "getElementById" $ [id] h id = pure $ toMaybe $ document ... "getElementById" $ [id]
querySelector :: String -> Effect (Maybe DOM.Element)
querySelector = (flip delay) h
where
h selector = pure $ toMaybe $ document ... "querySelector" $ [selector]
-- We just assume it works, so make sure it's in the html -- We just assume it works, so make sure it's in the html
getPortalHost :: R.Hooks DOM.Element getPortalHost :: R.Hooks DOM.Element
getPortalHost = R.unsafeHooksEffect $ delay unit $ \_ -> pure $ document ... "getElementById" $ ["portal"] getPortalHost = R.unsafeHooksEffect $ delay unit $ \_ -> pure $ document ... "getElementById" $ ["portal"]
...@@ -487,6 +492,12 @@ focus nEl = case toMaybe nEl of ...@@ -487,6 +492,12 @@ focus nEl = case toMaybe nEl of
Nothing -> pure unit Nothing -> pure unit
Just el -> el ... "focus" $ [] Just el -> el ... "focus" $ []
foreign import _scrollIntoView :: EffectFn1 DOM.Element Unit
scrollIntoView :: DOM.Element -> Effect Unit
scrollIntoView el = runEffectFn1 _scrollIntoView el
setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element
setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val
......
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