Commit 2bb24278 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] turns out createElement is not needed

It is enough to create a portal with that dummy ref-ed container.

This simplifies code and makes parentRef obsolete.
parent 3a1dc8f0
......@@ -38,7 +38,6 @@ type Props sigma forceatlas2 =
( elRef :: R.Ref (Nullable Element)
, forceAtlas2Settings :: forceatlas2
, graph :: Graph
, parentRef :: R.Ref (Nullable Element)
, sigmaSettings :: sigma
, sigmaRef :: R.Ref Sigma
)
......@@ -50,21 +49,21 @@ graphCpt :: forall s fa2. R.Component (Props s fa2)
graphCpt = R.hooksComponent "Graph" cpt
where
cpt props _ = do
R.useEffectOnce' $ do
el <- case R.readNullableRef props.elRef of
Just el -> do
pure el
Nothing -> do
let el = createElement "div"
setAttr el "style" "height: 95%"
setAttr el "id" "graph-cpt-root"
R.setRef props.elRef $ notNull $ el
pure el
-- R.useEffectOnce' $ do
-- el <- case R.readNullableRef props.elRef of
-- Just el -> do
-- pure el
-- Nothing -> do
-- let el = createElement "div"
-- setAttr el "style" "height: 95%"
-- setAttr el "id" "graph-cpt-root"
-- R.setRef props.elRef $ notNull $ el
-- pure el
case R.readNullableRef props.parentRef of
Nothing -> pure unit
Just parentEl -> R2.appendChild parentEl el
pure unit
-- case R.readNullableRef props.parentRef of
-- Nothing -> pure unit
-- Just parentEl -> R2.appendChild parentEl el
-- pure unit
R.useEffectOnce $ do
--log "[graphCpt] calling startSigmaEff"
......
......@@ -41,8 +41,7 @@ type LayoutProps =
)
type Props = (
graphParentRef :: R.Ref (Nullable Element)
, graph :: Maybe Graph.Graph | LayoutProps
graph :: Maybe Graph.Graph | LayoutProps
)
--------------------------------------------------------------
......@@ -53,11 +52,10 @@ explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
where
cpt {graphId, mCurrentRoute, treeId, session, sessions, frontends} _ = do
graphParentRef <- R.useRef null
useLoader graphId (getNodes session) (handler graphParentRef)
useLoader graphId (getNodes session) handler
where
handler graphParentRef loaded =
explorer {graphParentRef, graphId, mCurrentRoute, treeId, session, sessions, graph, frontends}
handler loaded =
explorer {graphId, mCurrentRoute, treeId, session, sessions, graph, frontends}
where graph = Just (convert loaded)
--------------------------------------------------------------
......@@ -67,7 +65,8 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props
explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where
cpt {graphParentRef, sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
cpt {sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
graphRef <- R.useRef null
controls <- Controls.useGraphControls
state <- useExplorerState
x /\ setX <- R.useState' 0
......@@ -87,8 +86,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ]
]
, row [ tree {mCurrentRoute, treeId} controls showLogin
, RH.div { ref: graphParentRef, id: "graph-view", className: "col-md-12" } [] -- graph parent
, mGraph graphParentRef controls.sigmaRef {graphId, graph}
, RH.div { ref: graphRef, id: "graph-view", className: "col-md-12", style: {height: "95%"} } [] -- graph container
, mGraph graphRef controls.sigmaRef {graphId, graph}
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, row [
]
......@@ -113,7 +112,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element
mGraph _ _ {graph: Nothing} = RH.div {} []
mGraph graphParentRef sigmaRef {graphId, graph: Just graph} = graphView graphParentRef sigmaRef {graphId, graph}
mGraph graphRef sigmaRef {graphId, graph: Just graph} = graphView graphRef sigmaRef {graphId, graph}
useExplorerState :: R.Hooks (Record GET.State)
useExplorerState = do pure {}
......@@ -140,18 +139,15 @@ type GraphProps = (
graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element
--graphView sigmaRef props = R.createElement (R.memo el memoCmp) props []
graphView parentRef sigmaRef props = R.createElement el props []
graphView elRef sigmaRef props = R.createElement el props []
where
--memoCmp props1 props2 = props1.graphId == props2.graphId
el = R.hooksComponent "GraphView" cpt
cpt {graphId, graph} _children = do
elRef <- R.useRef null
pure $ Graph.graph {
elRef
, forceAtlas2Settings: Graph.forceAtlas2Settings
, graph
, parentRef
, sigmaSettings: Graph.sigmaSettings
, sigmaRef: sigmaRef
}
......
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