Commit 83b75761 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[forest] refactoring of forest view with children

parent 2bdf5821
...@@ -35,7 +35,6 @@ import Gargantext.Routes (AppRoute(..)) ...@@ -35,7 +35,6 @@ import Gargantext.Routes (AppRoute(..))
import Gargantext.Sessions (Sessions, useSessions) import Gargantext.Sessions (Sessions, useSessions)
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
thisModule :: String thisModule :: String
thisModule = "Gargantext.Components.App" thisModule = "Gargantext.Components.App"
...@@ -67,10 +66,9 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -67,10 +66,9 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
let backends = fromFoldable defaultBackends let backends = fromFoldable defaultBackends
let ff f session = R.fragment [ f session, footer { session } ] let ff f session = R.fragment [ f session, footer { session } ]
let forested child = forestLayout { appReload: reload let forested = forestLayout { appReload: reload
, asyncTasksRef , asyncTasksRef
, backend , backend
, child
, frontends , frontends
, handed , handed
, route: fst route , route: fst route
...@@ -78,23 +76,28 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -78,23 +76,28 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, showLogin: snd showLogin , showLogin: snd showLogin
, treeReloadRef , treeReloadRef
} }
let defaultView _ = forested $ homeLayout { backend let defaultView _ = forested [
homeLayout { backend
, lang: LL_EN , lang: LL_EN
, publicBackend , publicBackend
, sessions , sessions
, visible: showLogin , visible: showLogin
} }
]
let mCurrentRoute = fst route let mCurrentRoute = fst route
let withSession sid f = maybe' defaultView (ff f) (Sessions.lookup sid (fst sessions)) let withSession sid f = maybe' defaultView (ff f) (Sessions.lookup sid (fst sessions))
let sessionUpdate s = snd sessions $ Sessions.Update s let sessionUpdate s = snd sessions $ Sessions.Update s
pure $ case fst showLogin of pure $ case fst showLogin of
true -> forested $ login { backend, backends, sessions, visible: showLogin } true -> forested [ login { backend, backends, sessions, visible: showLogin } ]
false -> false ->
case fst route of case fst route of
Annuaire sid nodeId -> withSession sid $ \session -> forested $ annuaireLayout { frontends, nodeId, session } Annuaire sid nodeId -> withSession sid $ \session -> forested [
ContactPage sid aId nodeId -> withSession sid $ \session -> forested $ annuaireUserLayout { annuaireLayout { frontends, nodeId, session }
]
ContactPage sid aId nodeId -> withSession sid $ \session -> forested [
annuaireUserLayout {
annuaireId: aId annuaireId: aId
, appReload: reload , appReload: reload
, asyncTasksRef , asyncTasksRef
...@@ -103,18 +106,30 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -103,18 +106,30 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, session , session
, treeReloadRef , treeReloadRef
} }
Corpus sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } ]
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested $ documentLayout { corpusId: Just corpusId, nodeId, listId, session } Corpus sid nodeId -> withSession sid $ \session -> forested [
Dashboard sid nodeId -> withSession sid $ \session -> forested $ dashboardLayout { nodeId, session } corpusLayout { nodeId, session }
]
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested [
documentLayout { corpusId: Just corpusId, nodeId, listId, session }
]
Dashboard sid nodeId -> withSession sid $ \session -> forested [
dashboardLayout { nodeId, session }
]
Document sid listId nodeId -> Document sid listId nodeId ->
withSession sid $ withSession sid $
\session -> forested $ documentLayout { corpusId: Nothing, nodeId, listId, session } \session -> forested [
Folder sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } documentLayout { corpusId: Nothing, nodeId, listId, session }
FolderPrivate sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } ]
FolderPublic sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } Folder sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
FolderShared sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } FolderPrivate sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
Home -> forested $ homeLayout { backend, lang: LL_EN, publicBackend, sessions, visible: showLogin } FolderPublic sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout { FolderShared sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
Home -> forested [
homeLayout { backend, lang: LL_EN, publicBackend, sessions, visible: showLogin }
]
Lists sid nodeId -> withSession sid $ \session -> forested [
listsLayout {
appReload: reload appReload: reload
, asyncTasksRef , asyncTasksRef
, nodeId , nodeId
...@@ -122,6 +137,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -122,6 +137,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, sessionUpdate , sessionUpdate
, treeReloadRef , treeReloadRef
} }
]
Login -> login { backend, backends, sessions, visible: showLogin } Login -> login { backend, backends, sessions, visible: showLogin }
PGraphExplorer sid graphId -> PGraphExplorer sid graphId ->
withSession sid $ withSession sid $
...@@ -137,13 +153,24 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -137,13 +153,24 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, sessions: (fst sessions) , sessions: (fst sessions)
, showLogin , showLogin
} }
RouteFile sid nodeId -> withSession sid $ \session -> forested $ fileLayout { nodeId, session } RouteFile sid nodeId -> withSession sid $ \session -> forested [ fileLayout { nodeId, session } ]
RouteFrameCalc sid nodeId -> withSession sid $ \session -> forested $ frameLayout { nodeId, nodeType: GT.NodeFrameCalc, session } RouteFrameCalc sid nodeId -> withSession sid $ \session -> forested [
RouteFrameWrite sid nodeId -> withSession sid $ \session -> forested $ frameLayout { nodeId, nodeType: GT.NodeFrameWrite, session } frameLayout { nodeId, nodeType: GT.NodeFrameCalc, session }
RouteFrameCode sid nodeId -> withSession sid $ \session -> forested $ frameLayout { nodeId, nodeType: GT.NodeFrameNotebook, session } ]
Team sid nodeId -> withSession sid $ \session -> forested $ corpusLayout { nodeId, session } RouteFrameWrite sid nodeId -> withSession sid $ \session -> forested [
Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { frontends, nodeId, session, sessionUpdate } frameLayout { nodeId, nodeType: GT.NodeFrameWrite, session }
UserPage sid nodeId -> withSession sid $ \session -> forested $ userLayout { ]
RouteFrameCode sid nodeId -> withSession sid $ \session -> forested [
frameLayout { nodeId, nodeType: GT.NodeFrameNotebook, session }
]
Team sid nodeId -> withSession sid $ \session -> forested [
corpusLayout { nodeId, session }
]
Texts sid nodeId -> withSession sid $ \session -> forested [
textsLayout { frontends, nodeId, session, sessionUpdate }
]
UserPage sid nodeId -> withSession sid $ \session -> forested [
userLayout {
appReload: reload appReload: reload
, asyncTasksRef , asyncTasksRef
, frontends , frontends
...@@ -151,6 +178,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -151,6 +178,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
, session , session
, treeReloadRef , treeReloadRef
} }
]
-- Simple layout does not accommodate the tree -- Simple layout does not accommodate the tree
simpleLayout :: R.State GT.Handed -> R.Element -> R.Element simpleLayout :: R.State GT.Handed -> R.Element -> R.Element
......
...@@ -118,7 +118,6 @@ type ForestLayoutProps = ( ...@@ -118,7 +118,6 @@ type ForestLayoutProps = (
appReload :: ReloadS appReload :: ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor) , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend) , backend :: R.State (Maybe Backend)
, child :: R.Element
, frontends :: Frontends , frontends :: Frontends
, handed :: R.State Handed , handed :: R.State Handed
, route :: AppRoute , route :: AppRoute
...@@ -127,8 +126,8 @@ type ForestLayoutProps = ( ...@@ -127,8 +126,8 @@ type ForestLayoutProps = (
, treeReloadRef :: R.Ref (Maybe ReloadS) , treeReloadRef :: R.Ref (Maybe ReloadS)
) )
forestLayout :: Record ForestLayoutProps -> R.Element forestLayout :: Record ForestLayoutProps -> Array R.Element -> R.Element
forestLayout props = R.createElement forestLayoutCpt props [] forestLayout props = R.createElement forestLayoutCpt props
forestLayoutCpt :: R.Component ForestLayoutProps forestLayoutCpt :: R.Component ForestLayoutProps
forestLayoutCpt = R.hooksComponentWithModule thisModule "forestLayout" cpt forestLayoutCpt = R.hooksComponentWithModule thisModule "forestLayout" cpt
...@@ -145,13 +144,12 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c ...@@ -145,13 +144,12 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c
cpt { appReload cpt { appReload
, asyncTasksRef , asyncTasksRef
, backend , backend
, child
, frontends , frontends
, handed , handed
, route , route
, sessions , sessions
, showLogin , showLogin
, treeReloadRef } _ = do , treeReloadRef } children = do
let ordering = let ordering =
case fst handed of case fst handed of
LeftHanded -> reverse LeftHanded -> reverse
...@@ -168,12 +166,18 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c ...@@ -168,12 +166,18 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c
, sessions , sessions
, showLogin , showLogin
, treeReloadRef } ] , treeReloadRef } ]
, mainPage child , mainPage children
] ]
mainPage :: Array R.Element -> R.Element
mainPage = R.createElement mainPageCpt {}
mainPage :: R.Element -> R.Element mainPageCpt :: R.Component ()
mainPage child = mainPageCpt = R.hooksComponentWithModule thisModule "mainPage" cpt
H.div {className: "col-md-10"} where
[ H.div {id: "page-wrapper"} cpt {} children = do
[ H.div {className: "container-fluid"} [ child ] ] ] pure $ H.div {className: "col-md-10"} [
H.div {id: "page-wrapper"} [
H.div {className: "container-fluid"} children
]
]
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