Commit 6d0d0db7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toestand] more refactoring fixes

parent 48f83762
module Gargantext.Components.App (app) where module Gargantext.Components.App (app) where
import Data.Maybe (Maybe(..))
import Prelude import Prelude
import Reactix as R
import Toestand as T
import Gargantext.Components.App.Data (emptyApp) import Gargantext.Components.App.Data (emptyApp)
import Gargantext.Components.Router (router) import Gargantext.Components.Router (router)
import Gargantext.Hooks (useHashRouter) import Gargantext.Hooks (useHashRouter)
import Gargantext.Router as Router import Gargantext.Router as Router
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Reactix as R import Gargantext.Utils.Reactix as R2
import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.App" here = R2.here "Gargantext.Components.App"
......
...@@ -45,33 +45,36 @@ import Gargantext.Utils.Toestand as T2 ...@@ -45,33 +45,36 @@ import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer" here = R2.here "Gargantext.Components.GraphExplorer"
type BaseProps = type BaseProps = (
( backend :: T.Cursor (Maybe Backend) backend :: T.Cursor (Maybe Backend)
, frontends :: Frontends , frontends :: Frontends
, graphId :: GET.GraphId , graphId :: GET.GraphId
, handed :: T.Cursor Types.Handed , handed :: T.Cursor Types.Handed
, route :: T.Cursor AppRoute , route :: T.Cursor AppRoute
, sessions :: T.Cursor Sessions , sessions :: T.Cursor Sessions
, showLogin :: T.Cursor Boolean , showLogin :: T.Cursor Boolean
, tasks :: T.Cursor (Maybe GAT.Reductor) ) , tasks :: T.Cursor (Maybe GAT.Reductor)
)
type LayoutLoaderProps = ( session :: R.Context Session | BaseProps ) type LayoutLoaderProps = ( session :: R.Context Session | BaseProps )
type LayoutProps = ( session :: Session, graphVersion :: GUR.ReloadS | BaseProps ) type LayoutProps = (
graphVersion :: GUR.ReloadS
, session :: Session
| BaseProps
)
type Props = type Props = (
( graph :: SigmaxT.SGraph graph :: SigmaxT.SGraph
, graphVersion :: GUR.ReloadS
, hyperdataGraph :: GET.HyperdataGraph , hyperdataGraph :: GET.HyperdataGraph
, mMetaData :: Maybe GET.MetaData , mMetaData :: Maybe GET.MetaData
, session :: Session
| LayoutProps | LayoutProps
) )
-------------------------------------------------------------- --------------------------------------------------------------
explorerLayoutLoader :: R2.Component LayoutLoaderProps explorerLayoutLoader :: R2.Component LayoutLoaderProps
explorerLayoutLoader props = R.createElement explorerLayoutLoaderCpt props [] explorerLayoutLoader = R.createElement explorerLayoutLoaderCpt
explorerLayoutLoaderCpt :: R.Component LayoutLoaderProps explorerLayoutLoaderCpt :: R.Component LayoutLoaderProps
explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where
...@@ -80,25 +83,28 @@ explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where ...@@ -80,25 +83,28 @@ explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where
session <- R.useContext props.session -- todo: ugh, props fiddling session <- R.useContext props.session -- todo: ugh, props fiddling
let base = RX.pick props :: Record BaseProps let base = RX.pick props :: Record BaseProps
let props' = Record.merge base { graphVersion, session } let props' = Record.merge base { graphVersion, session }
pure $ explorerLayout props' pure $ explorerLayout props' []
explorerLayout :: R2.Component LayoutProps explorerLayout :: R2.Component LayoutProps
explorerLayout props = R.createElement explorerLayoutCpt props [] explorerLayout = R.createElement explorerLayoutCpt
explorerLayoutCpt :: R.Component LayoutProps explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = here.component "explorerLayout" cpt where explorerLayoutCpt = here.component "explorerLayout" cpt where
cpt props@{ graphId, session, graphVersion } _ = do cpt props@{ backend
, graphId
, graphVersion
, session } _ = do
useLoader graphId (getNodes session graphVersion) handler useLoader graphId (getNodes session graphVersion) handler
where where
handler loaded = handler loaded = explorer (Record.merge props { graph, hyperdataGraph: loaded, mMetaData }) []
explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData }) -- explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData })
where where
GET.HyperdataGraph { graph: hyperdataGraph } = loaded GET.HyperdataGraph { graph: hyperdataGraph } = loaded
Tuple mMetaData graph = convert hyperdataGraph Tuple mMetaData graph = convert hyperdataGraph
-------------------------------------------------------------- --------------------------------------------------------------
explorer :: Record Props -> R.Element explorer :: R2.Component Props
explorer props = R.createElement explorerCpt props [] explorer = R.createElement explorerCpt
explorerCpt :: R.Component Props explorerCpt :: R.Component Props
explorerCpt = here.component "explorer" cpt explorerCpt = here.component "explorer" cpt
......
...@@ -14,7 +14,7 @@ import Gargantext.AsyncTasks as GAT ...@@ -14,7 +14,7 @@ import Gargantext.AsyncTasks as GAT
import Gargantext.Components.App.Data (Cursors) import Gargantext.Components.App.Data (Cursors)
import Gargantext.Components.Footer (footer) import Gargantext.Components.Footer (footer)
import Gargantext.Components.Forest (forestLayout) import Gargantext.Components.Forest (forestLayout)
import Gargantext.Components.GraphExplorer (explorerLayout) import Gargantext.Components.GraphExplorer (explorerLayoutLoader)
import Gargantext.Components.Lang (LandingLang(LL_EN)) import Gargantext.Components.Lang (LandingLang(LL_EN))
import Gargantext.Components.Login (login) import Gargantext.Components.Login (login)
import Gargantext.Components.Nodes.Annuaire (annuaireLayout) import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
...@@ -64,36 +64,35 @@ router props = R.createElement routerCpt props [] ...@@ -64,36 +64,35 @@ router props = R.createElement routerCpt props []
routerCpt :: R.Component Props routerCpt :: R.Component Props
routerCpt = here.component "root" cpt where routerCpt = here.component "root" cpt where
cpt props@{ cursors, tasks, ws } _ = do cpt props@{ cursors, tasks } _ = do
let session = R.createContext (unsafeCoerce {}) let session = R.createContext (unsafeCoerce {})
let sessionProps sId = Record.merge { session, sessionId: sId } props let sessionProps sId = Record.merge { session, sessionId: sId } props
let sessionNodeProps sId nId = Record.merge { nodeId: nId } $ sessionProps sId let sessionNodeProps sId nId = Record.merge { nodeId: nId } $ sessionProps sId
showLogin <- T.useLive T.unequal cursors.showLogin showLogin <- T.useLive T.unequal cursors.showLogin
route' <- T.useLive (T.changed notEq) cursors.route route' <- T.useLive T.unequal cursors.route
let props' = Record.merge props { route' } pure $ if showLogin then login' cursors
if showLogin then login' cursors
else case route' of else case route' of
GR.Annuaire s n -> annuaire (sessionNodeProps s n) [] GR.Annuaire s n -> annuaire (sessionNodeProps s n) []
GR.ContactPage s a n -> contact (Record.merge { annuaireId: a } $ sessionNodeProps s n) GR.ContactPage s a n -> contact (Record.merge { annuaireId: a } $ sessionNodeProps s n) []
GR.Corpus s n -> corpus (sessionNodeProps s n) GR.Corpus s n -> corpus (sessionNodeProps s n) []
GR.CorpusDocument s c l n -> corpusDocument (Record.merge { corpusId: c, listId: l } $ sessionNodeProps s n) GR.CorpusDocument s c l n -> corpusDocument (Record.merge { corpusId: c, listId: l } $ sessionNodeProps s n) []
GR.Dashboard s n -> dashboard (sessionNodeProps s n) GR.Dashboard s n -> dashboard (sessionNodeProps s n) []
GR.Document s l n -> document props s l n GR.Document s l n -> document (Record.merge { listId: l } $ sessionNodeProps s n) []
GR.Folder s n -> corpus (sessionNodeProps s n) GR.Folder s n -> corpus (sessionNodeProps s n) []
GR.FolderPrivate s n -> corpus (sessionNodeProps s n) GR.FolderPrivate s n -> corpus (sessionNodeProps s n) []
GR.FolderPublic s n -> corpus (sessionNodeProps s n) GR.FolderPublic s n -> corpus (sessionNodeProps s n) []
GR.FolderShared s n -> corpus (sessionNodeProps s n) GR.FolderShared s n -> corpus (sessionNodeProps s n) []
GR.Home -> home props GR.Home -> home props []
GR.Lists s n -> lists (sessionNodeProps s n) GR.Lists s n -> lists (sessionNodeProps s n) []
GR.Login -> login' cursors GR.Login -> login' cursors
GR.PGraphExplorer s g -> graphExplorer (sessionNodeProps s g) GR.PGraphExplorer s g -> graphExplorer (sessionNodeProps s g) []
GR.RouteFile s n -> routeFile (sessionNodeProps s n) GR.RouteFile s n -> routeFile (sessionNodeProps s n) []
GR.RouteFrameCalc s n -> routeFrame props s n NodeFrameCalc GR.RouteFrameCalc s n -> routeFrame (Record.merge { nodeType: NodeFrameCalc } $ sessionNodeProps s n) []
GR.RouteFrameCode s n -> routeFrame props s n NodeFrameNotebook GR.RouteFrameCode s n -> routeFrame (Record.merge { nodeType: NodeFrameNotebook } $ sessionNodeProps s n) []
GR.RouteFrameWrite s n -> routeFrame props s n NodeFrameWrite GR.RouteFrameWrite s n -> routeFrame (Record.merge { nodeType: NodeFrameWrite } $ sessionNodeProps s n) []
GR.Team s n -> team (sessionNodeProps s n) GR.Team s n -> team (sessionNodeProps s n) []
GR.Texts s n -> texts (sessionNodeProps s n) GR.Texts s n -> texts (sessionNodeProps s n) []
GR.UserPage s n -> user (sessionNodeProps s n) GR.UserPage s n -> user (sessionNodeProps s n) []
forested :: R2.Component Props forested :: R2.Component Props
forested = R.createElement forestedCpt forested = R.createElement forestedCpt
...@@ -124,10 +123,10 @@ annuaire = R.createElement annuaireCpt ...@@ -124,10 +123,10 @@ annuaire = R.createElement annuaireCpt
annuaireCpt :: R.Component SessionNodeProps annuaireCpt :: R.Component SessionNodeProps
annuaireCpt = here.component "annuaire" cpt where annuaireCpt = here.component "annuaire" cpt where
cpt props@{ nodeId, session, sessionId, tasks } _ = do cpt props@{ cursors, nodeId, session, sessionId, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ pure $ authed sessionProps $
forested props [ annuaireLayout { frontends, nodeId, session } ] forested { cursors, tasks } [ annuaireLayout { frontends, nodeId, session } ]
where frontends = defaultFrontends where frontends = defaultFrontends
corpus :: R2.Component SessionNodeProps corpus :: R2.Component SessionNodeProps
...@@ -142,7 +141,7 @@ corpusCpt = here.component "corpus" cpt where ...@@ -142,7 +141,7 @@ corpusCpt = here.component "corpus" cpt where
type CorpusDocumentProps = type CorpusDocumentProps =
( corpusId :: CorpusId ( corpusId :: CorpusId
, listID :: ListId , listId :: ListId
| SessionNodeProps | SessionNodeProps
) )
...@@ -152,11 +151,11 @@ corpusDocument = R.createElement corpusDocumentCpt ...@@ -152,11 +151,11 @@ corpusDocument = R.createElement corpusDocumentCpt
corpusDocumentCpt :: R.Component CorpusDocumentProps corpusDocumentCpt :: R.Component CorpusDocumentProps
corpusDocumentCpt = here.component "corpusDocument" cpt corpusDocumentCpt = here.component "corpusDocument" cpt
where where
cpt props@{ cursors, corpusId: corpusId', listID, nodeId, session, sessionId, tasks } _ = do cpt props@{ cursors, corpusId: corpusId', listId, nodeId, session, sessionId, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ pure $ authed sessionProps $
forested { cursors, tasks } forested { cursors, tasks }
[ documentMainLayout { mCorpusId: corpusId, listId: listID, nodeId, session } [] ] [ documentMainLayout { mCorpusId: corpusId, listId: listId, nodeId, session } [] ]
where corpusId = Just corpusId' where corpusId = Just corpusId'
dashboard :: R2.Component SessionNodeProps dashboard :: R2.Component SessionNodeProps
...@@ -209,6 +208,7 @@ listsCpt = here.component "lists" cpt where ...@@ -209,6 +208,7 @@ listsCpt = here.component "lists" cpt where
, sessionId , sessionId
, tasks } _ = do , tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
pure $ authed sessionProps $ pure $ authed sessionProps $
Lists.listsWithForest Lists.listsWithForest
{ forestProps: { backend { forestProps: { backend
...@@ -220,14 +220,21 @@ listsCpt = here.component "lists" cpt where ...@@ -220,14 +220,21 @@ listsCpt = here.component "lists" cpt where
, sessions , sessions
, showLogin , showLogin
, tasks } , tasks }
, listsProps: { nodeId, reloadRoot, reloadForest, session, tasks } , listsProps: { nodeId
, reloadRoot
, reloadForest
, session: session'
, sessionUpdate: \_ -> pure unit
, tasks }
} [] } []
where frontends = defaultFrontends where frontends = defaultFrontends
login' :: Cursors -> R.Element login' :: Cursors -> R.Element
login' { backend, sessions, showLogin: visible } = login' { backend, sessions, showLogin: visible } =
login { backend, sessions, visible login { backend
, backends: fromFoldable defaultBackends } , backends: fromFoldable defaultBackends
, sessions
, visible }
graphExplorer :: R2.Component SessionNodeProps graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt graphExplorer = R.createElement graphExplorerCpt
...@@ -235,19 +242,21 @@ graphExplorer = R.createElement graphExplorerCpt ...@@ -235,19 +242,21 @@ graphExplorer = R.createElement graphExplorerCpt
graphExplorerCpt :: R.Component SessionNodeProps graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where graphExplorerCpt = here.component "graphExplorer" cpt where
cpt props@{ cursors: { backend, handed, route, sessions, showLogin } cpt props@{ cursors: { backend, handed, route, sessions, showLogin }
, nodeId, session, tasks } _ = do , nodeId
, session
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ pure $ authed sessionProps $
simpleLayout { handed } simpleLayout { handed }
[ explorerLayout { backend [ explorerLayoutLoader { backend
, graphId: nodeId
, frontends , frontends
, graphId: nodeId
, handed , handed
, route , route
, session , session
, sessions , sessions
, showLogin , showLogin
, tasks } ] , tasks } [] ]
where frontends = defaultFrontends where frontends = defaultFrontends
routeFile :: R2.Component SessionNodeProps routeFile :: R2.Component SessionNodeProps
...@@ -301,6 +310,7 @@ textsCpt = here.component "texts" cpt ...@@ -301,6 +310,7 @@ textsCpt = here.component "texts" cpt
, sessionId , sessionId
, tasks } _ = do , tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
pure $ authed sessionProps $ pure $ authed sessionProps $
Texts.textsWithForest Texts.textsWithForest
{ forestProps: { backend { forestProps: { backend
...@@ -312,7 +322,9 @@ textsCpt = here.component "texts" cpt ...@@ -312,7 +322,9 @@ textsCpt = here.component "texts" cpt
, sessions , sessions
, showLogin , showLogin
, tasks } , tasks }
, textsProps: { frontends, nodeId, session } } , textsProps: { frontends
, nodeId
, session: session' } }
[] where frontends = defaultFrontends [] where frontends = defaultFrontends
user :: R2.Component SessionNodeProps user :: R2.Component SessionNodeProps
...@@ -320,12 +332,21 @@ user = R.createElement userCpt ...@@ -320,12 +332,21 @@ user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps userCpt :: R.Component SessionNodeProps
userCpt = here.component "user" cpt where userCpt = here.component "user" cpt where
cpt props@{ cursors: cursors@{ reloadRoot } cpt props@{ cursors: cursors@{ reloadForest, reloadRoot }
, nodeId, session, sessionId, tasks } _ = do , nodeId
, session
, sessionId
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
pure $ authed sessionProps $ pure $ authed sessionProps $
forested { cursors, tasks } forested { cursors, tasks }
[ userLayout { frontends, nodeId, reloadRoot, session, tasks } ] [ userLayout { frontends
, nodeId
, reloadForest
, reloadRoot
, session: session'
, tasks } ]
where frontends = defaultFrontends where frontends = defaultFrontends
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps ) type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
......
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