Commit a60c6c57 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[refactoring] some small refactoring

parent 7a2019fa
......@@ -97,13 +97,14 @@ type FolderProps =
folder :: R2.Component FolderProps
folder = R.createElement folderCpt
folderCpt :: R.Component FolderProps
folderCpt = here.component "folderCpt" cpt where
cpt {style, text, nodeId, sid, nodeType} _ = do
pure $ H.a {className: "btn btn-primary", href: "/#/" <> getFolderPath nodeType sid nodeId} [ H.i { className: icon style nodeType } []
pure $ H.a { className: "btn btn-primary"
, href: "/#/" <> getFolderPath nodeType sid nodeId }
[ H.i { className: icon style nodeType } []
, H.br {}
, H.text text]
, H.text text ]
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
......
......@@ -69,7 +69,6 @@ type LoaderProps = ( session :: Session, root :: ID | Common )
-- | Loads and renders the tree starting at the given root node id.
treeLoader :: R2.Component LoaderProps
treeLoader = R.createElement treeLoaderCpt
treeLoaderCpt :: R.Component LoaderProps
treeLoaderCpt = here.component "treeLoader" cpt where
-- treeLoaderCpt :: R.Memo LoaderProps
......@@ -96,7 +95,6 @@ type TreeProps = ( tree :: FTree | NodeProps )
tree :: R2.Leaf TreeProps
tree props = R.createElement treeCpt props []
treeCpt :: R.Component TreeProps
treeCpt = here.component "tree" cpt where
cpt p@{ reload, session, tree: NTree (LNode { id, name, nodeType }) children } _ = do
......@@ -134,7 +132,6 @@ type ChildrenTreeProps =
renderChildren :: R2.Component ChildrenTreeProps
renderChildren = R.createElement renderChildrenCpt
renderChildrenCpt :: R.Component ChildrenTreeProps
renderChildrenCpt = here.component "renderChildren" cpt where
cpt p@{ childProps: { folderOpen } } _ = do
......@@ -147,7 +144,6 @@ renderChildrenCpt = here.component "renderChildren" cpt where
renderTreeChildren :: R2.Component ChildrenTreeProps
renderTreeChildren = R.createElement renderTreeChildrenCpt
renderTreeChildrenCpt :: R.Component ChildrenTreeProps
renderTreeChildrenCpt = here.component "renderTreeChildren" cpt where
cpt p@{ childProps: { children'
......@@ -180,7 +176,6 @@ type ChildLoaderProps = ( id :: ID, render :: R2.Leaf TreeProps | NodeProps )
childLoader :: R2.Component ChildLoaderProps
childLoader = R.createElement childLoaderCpt
childLoaderCpt :: R.Component ChildLoaderProps
childLoaderCpt = here.component "childLoader" cpt where
cpt p@{ render } _ = do
......
......@@ -39,7 +39,6 @@ type SubTreeParamsProps =
subTreeView :: R2.Component SubTreeParamsProps
subTreeView = R.createElement subTreeViewCpt
subTreeViewCpt :: R.Component SubTreeParamsProps
subTreeViewCpt = here.component "subTreeView" cpt
where
......@@ -86,7 +85,6 @@ type CorpusTreeProps =
subTreeViewLoaded :: R2.Component CorpusTreeProps
subTreeViewLoaded = R.createElement subTreeViewLoadedCpt
subTreeViewLoadedCpt :: R.Component CorpusTreeProps
subTreeViewLoadedCpt = here.component "subTreeViewLoaded" cpt
where
......@@ -107,7 +105,6 @@ newtype CorpusTreeRenderProps = CorpusTreeRenderProps
subTreeTreeView :: CorpusTreeRenderProps -> Array R.Element -> R.Element
subTreeTreeView = R2.ntCreateElement subTreeTreeViewCpt
subTreeTreeViewCpt :: R2.NTComponent CorpusTreeRenderProps
subTreeTreeViewCpt = here.ntComponent "subTreeTreeView" cpt where
cpt (CorpusTreeRenderProps p@{ action
......
......@@ -32,10 +32,9 @@ import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Data.Louvain as Louvain
import Gargantext.Ends (Frontends, Backend)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Routes (SessionRoute(NodeAPI), AppRoute)
import Gargantext.Sessions (OpenNodes, Session, Sessions, get)
import Gargantext.Sessions (Session, Sessions, get)
import Gargantext.Types as Types
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
......@@ -76,7 +75,6 @@ type Props =
--------------------------------------------------------------
explorerLayout :: R2.Component LayoutProps
explorerLayout = R.createElement explorerLayoutCpt
explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = here.component "explorerLayout" cpt where
cpt props@{ backend, boxes: { graphVersion }, graphId, session } _ = do
......@@ -84,15 +82,13 @@ explorerLayoutCpt = here.component "explorerLayout" cpt where
useLoader graphId (getNodes session graphVersion') handler
where
handler loaded = explorerWriteGraph (Record.merge props { graph, hyperdataGraph: loaded, mMetaData' }) []
-- explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData })
handler loaded@(GET.HyperdataGraph { graph: hyperdataGraph }) =
explorerWriteGraph (Record.merge props { graph, hyperdataGraph: loaded, mMetaData' }) []
where
GET.HyperdataGraph { graph: hyperdataGraph } = loaded
Tuple mMetaData' graph = convert hyperdataGraph
explorerWriteGraph :: R2.Component GraphWriteProps
explorerWriteGraph = R.createElement explorerWriteGraphCpt
explorerWriteGraphCpt :: R.Component GraphWriteProps
explorerWriteGraphCpt = here.component "explorerWriteGraph" cpt where
cpt props@{ boxes: { sidePanelGraph, sidePanelState }
......@@ -108,19 +104,11 @@ explorerWriteGraphCpt = here.component "explorerWriteGraph" cpt where
, showControls: false
, sideTab: GET.SideTabLegend }) sidePanelGraph
-- { mGraph, mMetaData, sideTab } <- GEST.focusedSidePanel sidePanelGraph
-- R.useEffect' $ do
-- here.log2 "writing graph" graph
-- T.write_ (Just graph) mGraph
-- T.write_ mMetaData' mMetaData
pure $ explorer (RX.pick props :: Record Props) []
--------------------------------------------------------------
explorer :: R2.Component Props
explorer = R.createElement explorerCpt
explorerCpt :: R.Component Props
explorerCpt = here.component "explorer" cpt
where
......@@ -163,32 +151,26 @@ explorerCpt = here.component "explorer" cpt
, sidePanelState
}
multiSelectEnabled' <- T.useLive T.unequal controls.multiSelectEnabled
showTree' <- T.useLive T.unequal controls.showTree
multiSelectEnabledRef <- R.useRef multiSelectEnabled'
forestOpen <- T.useBox $ (Set.empty :: OpenNodes)
R.useEffectOnce' $ do
R2.loadLocalStorageState R2.openNodesKey forestOpen
T.listen (R2.listenLocalStorageState R2.openNodesKey) forestOpen
R.useEffect' $ do
let readData = R.readRef dataRef
let gv = R.readRef graphVersionRef
if SigmaxT.eqGraph readData graph then
pure unit
else do
-- Graph data changed, reinitialize sigma.
let rSigma = R.readRef controls.sigmaRef
Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph
R.setRef graphVersionRef graphVersion'
-- Reinitialize bunch of state as well.
T.write_ SigmaxT.emptyNodeIds controls.removedNodeIds
T.write_ SigmaxT.emptyNodeIds controls.selectedNodeIds
T.write_ SigmaxT.EShow controls.showEdges
T.write_ forceAtlasS controls.forceAtlasState
T.write_ Graph.Init controls.graphStage
T.write_ Types.InitialClosed controls.sidePanelState
-- R.useEffect' $ do
-- let readData = R.readRef dataRef
-- let gv = R.readRef graphVersionRef
-- if SigmaxT.eqGraph readData graph then
-- pure unit
-- else do
-- -- Graph data changed, reinitialize sigma.
-- let rSigma = R.readRef controls.sigmaRef
-- Sigmax.cleanupSigma rSigma "explorerCpt"
-- R.setRef dataRef graph
-- R.setRef graphVersionRef graphVersion'
-- -- Reinitialize bunch of state as well.
-- T.write_ SigmaxT.emptyNodeIds controls.removedNodeIds
-- T.write_ SigmaxT.emptyNodeIds controls.selectedNodeIds
-- T.write_ SigmaxT.EShow controls.showEdges
-- T.write_ forceAtlasS controls.forceAtlasState
-- T.write_ Graph.Init controls.graphStage
-- T.write_ Types.InitialClosed controls.sidePanelState
pure $
RH.div { className: "graph-meta-container" }
......@@ -221,9 +203,8 @@ type TopBar =
boxes :: Boxes
)
topBar :: R2.Component TopBar
topBar = R.createElement topBarCpt
topBar :: R2.Leaf TopBar
topBar p = R.createElement topBarCpt p []
topBarCpt :: R.Component TopBar
topBarCpt = here.component "topBar" cpt where
cpt { boxes: { showTree
......@@ -268,9 +249,7 @@ type GraphProps = (
)
graphView :: R2.Component GraphProps
--graphView sigmaRef props = R.createElement (R.memo el memoCmp) props []
graphView = R.createElement graphViewCpt
graphViewCpt :: R.Component GraphProps
graphViewCpt = here.component "graphView" cpt
where
......
......@@ -67,7 +67,6 @@ initialLocalControls = do
controls :: R2.Component Controls
controls = R.createElement controlsCpt
controlsCpt :: R.Component Controls
controlsCpt = here.component "controls" cpt
where
......
......@@ -34,7 +34,7 @@ sizeButtonCpt :: R.Component Props
sizeButtonCpt = here.component "sizeButton" cpt where
cpt { state, caption, min, max, onChange } _ = do
defaultValue <- T.useLive T.unequal state
pure $ H.span { class: "range-simple" }
pure $ H.span { className: "range-simple" }
[ H.label {} [ R2.small {} [ H.text caption ] ]
, H.input { type: "range"
, className: "form-control"
......
......@@ -191,7 +191,6 @@ type ContactCellsProps =
contactCells :: Record ContactCellsProps -> R.Element
contactCells p = R.createElement contactCellsCpt p []
contactCellsCpt :: R.Component ContactCellsProps
contactCellsCpt = here.component "contactCells" cpt where
cpt { annuaireId, frontends, session
......
......@@ -63,18 +63,18 @@ routerCpt = here.component "router" cpt where
RightHanded -> "right-handed"
pure $ R.fragment
([ loginModal { boxes } []
, topBar { boxes } [] ] <>
([ loginModal { boxes }
, topBar { boxes } ] <>
[ H.div { className: handedClassName } $ reverseHanded handed' $
[ forest { boxes } []
, mainPage { boxes } []
, sidePanel { boxes } []
[ forest { boxes }
, mainPage { boxes }
, sidePanel { boxes }
]
])
loginModal :: R2.Component Props
loginModal = R.createElement loginModalCpt
loginModal :: R2.Leaf Props
loginModal p = R.createElement loginModalCpt p []
loginModalCpt :: R.Component Props
loginModalCpt = here.component "loginModal" cpt
where
......@@ -83,8 +83,8 @@ loginModalCpt = here.component "loginModal" cpt
pure $ if showLogin' then login' boxes else H.div {} []
topBar :: R2.Component Props
topBar = R.createElement topBarCpt
topBar :: R2.Leaf Props
topBar p = R.createElement topBarCpt p []
topBarCpt :: R.Component Props
topBarCpt = here.component "topBar" cpt where
cpt props@{ boxes: boxes@{ handed
......@@ -92,20 +92,20 @@ topBarCpt = here.component "topBar" cpt where
route' <- T.useLive T.unequal boxes.route
let children = case route' of
GR.PGraphExplorer s g -> [ GraphExplorer.topBar { boxes } [] ]
GR.PGraphExplorer s g -> [ GraphExplorer.topBar { boxes } ]
_ -> []
pure $ TopBar.topBar { handed } children
mainPage :: R2.Component Props
mainPage = R.createElement mainPageCpt
mainPage :: R2.Leaf Props
mainPage p = R.createElement mainPageCpt p []
mainPageCpt :: R.Component Props
mainPageCpt = here.component "mainPage" cpt where
cpt { boxes } _ = do
pure $ MainPage.mainPage { boxes } [ renderRoute { boxes } [] ]
pure $ MainPage.mainPage { boxes } [ renderRoute { boxes } ]
forest :: R2.Component Props
forest = R.createElement forestCpt
forest :: R2.Leaf Props
forest p = R.createElement forestCpt p []
forestCpt :: R.Component Props
forestCpt = here.component "forest" cpt where
cpt props@{ boxes: boxes@{ backend
......@@ -132,8 +132,8 @@ forestCpt = here.component "forest" cpt where
, showTree
, tasks } []
sidePanel :: R2.Component Props
sidePanel = R.createElement sidePanelCpt
sidePanel :: R2.Leaf Props
sidePanel p = R.createElement sidePanelCpt p []
sidePanelCpt :: R.Component Props
sidePanelCpt = here.component "sidePanel" cpt where
cpt props@{ boxes: boxes@{ graphVersion
......@@ -153,8 +153,8 @@ sidePanelCpt = here.component "sidePanel" cpt where
Opened -> pure $ openedSidePanel (Record.merge { session: s } props) []
_ -> pure $ H.div {} []
renderRoute :: R2.Component Props
renderRoute = R.createElement renderRouteCpt
renderRoute :: R2.Leaf Props
renderRoute p = R.createElement renderRouteCpt p []
renderRouteCpt :: R.Component Props
renderRouteCpt = here.component "renderRoute" cpt where
cpt props@{ boxes } _ = do
......@@ -212,7 +212,6 @@ authedCpt = here.component "authed" cpt where
openedSidePanel :: R2.Component (WithSession Props)
openedSidePanel = R.createElement openedSidePanelCpt
openedSidePanelCpt :: R.Component (WithSession Props)
openedSidePanelCpt = here.component "openedSidePanel" cpt where
cpt props@{ boxes: boxes@{ graphVersion
......@@ -262,7 +261,6 @@ openedSidePanelCpt = here.component "openedSidePanel" cpt where
annuaire :: R2.Component SessionNodeProps
annuaire = R.createElement annuaireCpt
annuaireCpt :: R.Component SessionNodeProps
annuaireCpt = here.component "annuaire" cpt where
cpt props@{ boxes, nodeId } _ = do
......@@ -274,7 +272,6 @@ annuaireCpt = here.component "annuaire" cpt where
corpus :: R2.Component SessionNodeProps
corpus = R.createElement corpusCpt
corpusCpt :: R.Component SessionNodeProps
corpusCpt = here.component "corpus" cpt where
cpt props@{ boxes, nodeId } _ = do
......@@ -290,7 +287,6 @@ type CorpusDocumentProps =
corpusDocument :: R2.Component CorpusDocumentProps
corpusDocument = R.createElement corpusDocumentCpt
corpusDocumentCpt :: R.Component CorpusDocumentProps
corpusDocumentCpt = here.component "corpusDocument" cpt
where
......@@ -304,7 +300,6 @@ corpusDocumentCpt = here.component "corpusDocument" cpt
dashboard :: R2.Component SessionNodeProps
dashboard = R.createElement dashboardCpt
dashboardCpt :: R.Component SessionNodeProps
dashboardCpt = here.component "dashboard" cpt
where
......@@ -317,7 +312,6 @@ type DocumentProps = ( listId :: ListId | SessionNodeProps )
document :: R2.Component DocumentProps
document = R.createElement documentCpt
documentCpt :: R.Component DocumentProps
documentCpt = here.component "document" cpt where
cpt props@{ boxes, listId, nodeId } _ = do
......@@ -330,7 +324,6 @@ documentCpt = here.component "document" cpt where
graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt
graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where
cpt props@{ boxes: boxes@{ backend
......@@ -344,7 +337,6 @@ graphExplorerCpt = here.component "graphExplorer" cpt where
, nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session ->
-- simpleLayout { handed }
GraphExplorer.explorerLayout { backend
, boxes
, frontends: defaultFrontends
......@@ -358,7 +350,6 @@ graphExplorerCpt = here.component "graphExplorer" cpt where
home :: R2.Component Props
home = R.createElement homeCpt
homeCpt :: R.Component Props
homeCpt = here.component "home" cpt where
cpt props@{ boxes: boxes@{ sessions, showLogin } } _ = do
......@@ -366,7 +357,6 @@ homeCpt = here.component "home" cpt where
lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
listsCpt = here.component "lists" cpt where
cpt props@{ boxes: { backend
......@@ -418,7 +408,6 @@ type RouteFrameProps = (
routeFrame :: R2.Component RouteFrameProps
routeFrame = R.createElement routeFrameCpt
routeFrameCpt :: R.Component RouteFrameProps
routeFrameCpt = here.component "routeFrame" cpt where
cpt props@{ boxes, nodeId, nodeType } _ = do
......@@ -428,7 +417,6 @@ routeFrameCpt = here.component "routeFrame" cpt where
team :: R2.Component SessionNodeProps
team = R.createElement teamCpt
teamCpt :: R.Component SessionNodeProps
teamCpt = here.component "team" cpt where
cpt props@{ boxes, nodeId } _ = do
......@@ -438,7 +426,6 @@ teamCpt = here.component "team" cpt where
texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt
textsCpt :: R.Component SessionNodeProps
textsCpt = here.component "texts" cpt
where
......@@ -464,7 +451,6 @@ textsCpt = here.component "texts" cpt
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
userCpt = here.component "user" cpt where
cpt props@{ boxes: boxes@{ reloadForest
......@@ -488,7 +474,6 @@ type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
contact :: R2.Component ContactProps
contact = R.createElement contactCpt
contactCpt :: R.Component ContactProps
contactCpt = here.component "contact" cpt where
cpt props@{ annuaireId
......
module Gargantext.Utils where
import DOM.Simple.Window (window)
import Data.Either (Either(..))
import Data.Foldable (class Foldable, foldr)
import Data.Lens (Lens', lens)
......@@ -10,6 +9,7 @@ import Data.Set as Set
import Data.Sequence.Ordered as OSeq
import Data.String as S
import Data.Unfoldable (class Unfoldable)
import DOM.Simple.Window (window)
import Effect (Effect)
import FFI.Simple ((..))
import FFI.Simple.Functions (delay)
......
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