Commit 217a2f36 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toestand] fixes to session context props for components

parent e5eabd49
module Gargantext.Components.Nodes.Annuaire.User module Gargantext.Components.Nodes.Annuaire.User
( module Gargantext.Components.Nodes.Annuaire.User.Contacts.Types ( module Gargantext.Components.Nodes.Annuaire.User.Contacts.Types
, userLayout , userLayout
, userLayoutSessionContext
) )
where where
...@@ -13,6 +14,8 @@ import Effect.Aff (Aff, launchAff_) ...@@ -13,6 +14,8 @@ import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record
import Record.Extra as REX
import Toestand as T import Toestand as T
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
...@@ -23,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types as LT ...@@ -23,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types as LT
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, get, put, sessionId) import Gargantext.Sessions (WithSession, WithSessionContext, Session, get, put, sessionId)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Reload as GUR
...@@ -147,20 +150,34 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt ...@@ -147,20 +150,34 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
listElement :: Array R.Element -> R.Element listElement :: Array R.Element -> R.Element
listElement = H.li { className: "list-group-item justify-content-between" } listElement = H.li { className: "list-group-item justify-content-between" }
type LayoutProps = type LayoutNoSessionProps =
( frontends :: Frontends ( frontends :: Frontends
, nodeId :: Int , nodeId :: Int
, reloadForest :: T.Box T2.Reload , reloadForest :: T.Box T2.Reload
, reloadRoot :: T.Box T2.Reload , reloadRoot :: T.Box T2.Reload
, session :: Session
, tasks :: T.Box (Maybe GAT.Reductor) , tasks :: T.Box (Maybe GAT.Reductor)
) )
type LayoutProps = WithSession LayoutNoSessionProps
type LayoutSessionContextProps = WithSessionContext LayoutNoSessionProps
type KeyLayoutProps = ( type KeyLayoutProps = (
key :: String key :: String
| LayoutProps | LayoutProps
) )
userLayoutSessionContext :: R2.Component LayoutSessionContextProps
userLayoutSessionContext = R.createElement userLayoutSessionContextCpt
userLayoutSessionContextCpt :: R.Component LayoutSessionContextProps
userLayoutSessionContextCpt = here.component "userLayoutSessionContext" cpt
where
cpt props@{ session } _ = do
session' <- R.useContext session
pure $ userLayout (Record.merge { session: session' } $ (REX.pick props :: Record LayoutNoSessionProps)) []
userLayout :: R2.Component LayoutProps userLayout :: R2.Component LayoutProps
userLayout = R.createElement userLayoutCpt userLayout = R.createElement userLayoutCpt
......
...@@ -9,6 +9,7 @@ import Effect.Aff (launchAff_) ...@@ -9,6 +9,7 @@ import Effect.Aff (launchAff_)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
import Record.Extra as REX
import Toestand as T import Toestand as T
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
...@@ -25,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types ...@@ -25,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types
import Gargantext.Components.Table as Table import Gargantext.Components.Table as Table
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session, sessionId, getCacheState, setCacheState) import Gargantext.Sessions (WithSession, WithSessionContext, Session, sessionId, getCacheState, setCacheState)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
...@@ -38,6 +39,23 @@ type ListsWithForest = ...@@ -38,6 +39,23 @@ type ListsWithForest =
, listsProps :: Record CommonProps , listsProps :: Record CommonProps
) )
type ListsWithForestSessionContext =
( forestProps :: Record Forest.Props
, listsProps :: Record CommonPropsSessionContext )
listsWithForestSessionContext :: R2.Component ListsWithForestSessionContext
listsWithForestSessionContext = R.createElement listsWithForestSessionContextCpt
listsWithForestSessionContextCpt :: R.Component ListsWithForestSessionContext
listsWithForestSessionContextCpt = here.component "listsWithForestSessionContext" cpt where
cpt { forestProps, listsProps: listsProps@{ session } } _ = do
session' <- R.useContext session
pure $ listsWithForest
{ forestProps
, listsProps: Record.merge { session: session' } $ (REX.pick listsProps :: Record CommonPropsNoSession)
} []
listsWithForest :: R2.Component ListsWithForest listsWithForest :: R2.Component ListsWithForest
listsWithForest = R.createElement listsWithForestCpt listsWithForest = R.createElement listsWithForestCpt
...@@ -67,15 +85,18 @@ topBarCpt = here.component "topBar" cpt where ...@@ -67,15 +85,18 @@ topBarCpt = here.component "topBar" cpt where
-- ] -- ]
-- ] -- head (goes to top bar) -- ] -- head (goes to top bar)
type CommonProps = type CommonPropsNoSession =
( nodeId :: Int ( nodeId :: Int
, reloadForest :: T.Box T2.Reload , reloadForest :: T.Box T2.Reload
, reloadRoot :: T.Box T2.Reload , reloadRoot :: T.Box T2.Reload
, session :: Session
, sessionUpdate :: Session -> Effect Unit , sessionUpdate :: Session -> Effect Unit
, tasks :: T.Box (Maybe GAT.Reductor) , tasks :: T.Box (Maybe GAT.Reductor)
) )
type CommonProps = WithSession CommonPropsNoSession
type CommonPropsSessionContext = WithSessionContext CommonPropsNoSession
type Props = ( controls :: Record ListsLayoutControls | CommonProps ) type Props = ( controls :: Record ListsLayoutControls | CommonProps )
type WithTreeProps = ( handed :: GT.Handed | Props ) type WithTreeProps = ( handed :: GT.Handed | Props )
......
...@@ -13,6 +13,7 @@ import Effect.Aff (launchAff_) ...@@ -13,6 +13,7 @@ import Effect.Aff (launchAff_)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
import Record.Extra as REX
import Gargantext.Components.DocsTable as DT import Gargantext.Components.DocsTable as DT
import Gargantext.Components.Forest as Forest import Gargantext.Components.Forest as Forest
...@@ -32,7 +33,7 @@ import Gargantext.Components.Nodes.Texts.Types ...@@ -32,7 +33,7 @@ import Gargantext.Components.Nodes.Texts.Types
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table import Gargantext.Components.Table as Table
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session, sessionId, getCacheState) import Gargantext.Sessions (WithSession, WithSessionContext, Session, sessionId, getCacheState)
import Gargantext.Types (CTabNgramType(..), ListId, NodeID, TabSubType(..), TabType(..)) import Gargantext.Types (CTabNgramType(..), ListId, NodeID, TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -45,6 +46,24 @@ type TextsWithForest = ( ...@@ -45,6 +46,24 @@ type TextsWithForest = (
, textsProps :: Record CommonProps , textsProps :: Record CommonProps
) )
type TextsWithForestSessionContext =
( forestProps :: Record Forest.Props
, textsProps :: Record CommonPropsSessionContext )
textsWithForestSessionContext :: R2.Component TextsWithForestSessionContext
textsWithForestSessionContext = R.createElement textsWithForestSessionContextCpt
textsWithForestSessionContextCpt :: R.Component TextsWithForestSessionContext
textsWithForestSessionContextCpt = here.component "textsWithForestSessionContext" cpt
where
cpt { forestProps, textsProps: textsProps@{ session } } _ = do
session' <- R.useContext session
pure $ textsWithForest
{ forestProps
, textsProps: Record.merge { session: session' } $ (REX.pick textsProps :: Record CommonPropsNoSession)
} []
textsWithForest :: R2.Component TextsWithForest textsWithForest :: R2.Component TextsWithForest
textsWithForest = R.createElement textsWithForestCpt textsWithForest = R.createElement textsWithForestCpt
...@@ -80,12 +99,14 @@ topBarCpt = here.component "topBar" cpt ...@@ -80,12 +99,14 @@ topBarCpt = here.component "topBar" cpt
type CommonProps = ( type CommonPropsNoSession = (
frontends :: Frontends frontends :: Frontends
, nodeId :: NodeID , nodeId :: NodeID
, session :: Session
) )
type CommonProps = WithSession CommonPropsNoSession
type CommonPropsSessionContext = WithSessionContext CommonPropsNoSession
type Props = ( controls :: Record TextsLayoutControls | CommonProps ) type Props = ( controls :: Record TextsLayoutControls | CommonProps )
textsLayout :: R2.Component Props textsLayout :: R2.Component Props
......
...@@ -2,7 +2,6 @@ module Gargantext.Components.Router (router) where ...@@ -2,7 +2,6 @@ module Gargantext.Components.Router (router) where
import Data.Array (fromFoldable) import Data.Array (fromFoldable)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log2)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record import Record as Record
...@@ -20,7 +19,7 @@ import Gargantext.Components.GraphExplorer (explorerLayoutLoader) ...@@ -20,7 +19,7 @@ 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)
import Gargantext.Components.Nodes.Annuaire.User (userLayout) import Gargantext.Components.Nodes.Annuaire.User (userLayoutSessionContext)
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout) import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
import Gargantext.Components.Nodes.Corpus (corpusLayout) import Gargantext.Components.Nodes.Corpus (corpusLayout)
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout) import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
...@@ -112,15 +111,13 @@ forestedCpt = here.component "forested" cpt ...@@ -112,15 +111,13 @@ forestedCpt = here.component "forested" cpt
, showLogin , showLogin
, tasks } children , tasks } children
authed :: Record SessionProps -> (Unit -> R.Element) -> R.Element authed :: Record SessionProps -> R.Element -> R.Element
authed props@{ boxes: { sessions }, session, sessionId, tasks } content = authed props@{ boxes: { sessions }, session, sessionId, tasks } content =
sessionWrapper { fallback: home homeProps [] sessionWrapper { fallback: home homeProps []
, context: session , context: session
, render
, sessionId , sessionId
, sessions } [] , sessions } [ content, footer {} [] ]
where where
render _ = [ content unit, footer {} [] ]
homeProps = RE.pick props :: Record Props homeProps = RE.pick props :: Record Props
annuaire :: R2.Component SessionNodeProps annuaire :: R2.Component SessionNodeProps
...@@ -130,7 +127,7 @@ annuaireCpt :: R.Component SessionNodeProps ...@@ -130,7 +127,7 @@ annuaireCpt :: R.Component SessionNodeProps
annuaireCpt = here.component "annuaire" cpt where annuaireCpt = here.component "annuaire" cpt where
cpt props@{ boxes, nodeId, session, sessionId, tasks } _ = do cpt props@{ boxes, 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 { boxes, tasks } [ annuaireLayout { frontends, nodeId, session } ] forested { boxes, tasks } [ annuaireLayout { frontends, nodeId, session } ]
where frontends = defaultFrontends where frontends = defaultFrontends
...@@ -141,7 +138,7 @@ corpusCpt :: R.Component SessionNodeProps ...@@ -141,7 +138,7 @@ corpusCpt :: R.Component SessionNodeProps
corpusCpt = here.component "corpus" cpt where corpusCpt = here.component "corpus" cpt where
cpt props@{ boxes, nodeId, session, tasks } _ = do cpt props@{ boxes, nodeId, session, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } [ corpusLayout { nodeId, session } ] forested { boxes, tasks } [ corpusLayout { nodeId, session } ]
type CorpusDocumentProps = type CorpusDocumentProps =
...@@ -158,7 +155,7 @@ corpusDocumentCpt = here.component "corpusDocument" cpt ...@@ -158,7 +155,7 @@ corpusDocumentCpt = here.component "corpusDocument" cpt
where where
cpt props@{ boxes, corpusId: corpusId', listId, nodeId, session, sessionId, tasks } _ = do cpt props@{ boxes, 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 { boxes, tasks } forested { boxes, tasks }
[ documentMainLayout { mCorpusId: corpusId, listId: listId, nodeId, session } [] ] [ documentMainLayout { mCorpusId: corpusId, listId: listId, nodeId, session } [] ]
where corpusId = Just corpusId' where corpusId = Just corpusId'
...@@ -171,7 +168,7 @@ dashboardCpt = here.component "dashboard" cpt ...@@ -171,7 +168,7 @@ dashboardCpt = here.component "dashboard" cpt
where where
cpt props@{ boxes, nodeId, session, tasks } _ = do cpt props@{ boxes, nodeId, session, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } [ dashboardLayout { nodeId, session } [] ] forested { boxes, tasks } [ dashboardLayout { nodeId, session } [] ]
type DocumentProps = ( listId :: ListId | SessionNodeProps ) type DocumentProps = ( listId :: ListId | SessionNodeProps )
...@@ -183,7 +180,7 @@ documentCpt :: R.Component DocumentProps ...@@ -183,7 +180,7 @@ documentCpt :: R.Component DocumentProps
documentCpt = here.component "document" cpt where documentCpt = here.component "document" cpt where
cpt props@{ listId, nodeId, session, sessionId, tasks, boxes } _ = do cpt props@{ listId, nodeId, session, sessionId, tasks, boxes } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } forested { boxes, tasks }
[ documentMainLayout { listId, nodeId, mCorpusId, session } [] ] [ documentMainLayout { listId, nodeId, mCorpusId, session } [] ]
where mCorpusId = Nothing where mCorpusId = Nothing
...@@ -214,9 +211,8 @@ listsCpt = here.component "lists" cpt where ...@@ -214,9 +211,8 @@ 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.listsWithForestSessionContext
Lists.listsWithForest
{ forestProps: { backend { forestProps: { backend
, forestOpen , forestOpen
, frontends , frontends
...@@ -230,7 +226,7 @@ listsCpt = here.component "lists" cpt where ...@@ -230,7 +226,7 @@ listsCpt = here.component "lists" cpt where
, listsProps: { nodeId , listsProps: { nodeId
, reloadRoot , reloadRoot
, reloadForest , reloadForest
, session: session' , session
, sessionUpdate: \_ -> pure unit , sessionUpdate: \_ -> pure unit
, tasks } , tasks }
} [] } []
...@@ -253,7 +249,7 @@ graphExplorerCpt = here.component "graphExplorer" cpt where ...@@ -253,7 +249,7 @@ graphExplorerCpt = here.component "graphExplorer" cpt where
, session , session
, tasks } _ = do , 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 }
[ explorerLayoutLoader { backend [ explorerLayoutLoader { backend
, frontends , frontends
...@@ -273,7 +269,7 @@ routeFileCpt :: R.Component SessionNodeProps ...@@ -273,7 +269,7 @@ routeFileCpt :: R.Component SessionNodeProps
routeFileCpt = here.component "routeFile" cpt where routeFileCpt = here.component "routeFile" cpt where
cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } [ fileLayout { nodeId, session } ] forested { boxes, tasks } [ fileLayout { nodeId, session } ]
type RouteFrameProps = ( type RouteFrameProps = (
...@@ -288,7 +284,7 @@ routeFrameCpt :: R.Component RouteFrameProps ...@@ -288,7 +284,7 @@ routeFrameCpt :: R.Component RouteFrameProps
routeFrameCpt = here.component "routeFrame" cpt where routeFrameCpt = here.component "routeFrame" cpt where
cpt props@{ nodeId, nodeType, session, sessionId, boxes, tasks } _ = do cpt props@{ nodeId, nodeType, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } [ frameLayout { nodeId, nodeType, session } ] forested { boxes, tasks } [ frameLayout { nodeId, nodeType, session } ]
team :: R2.Component SessionNodeProps team :: R2.Component SessionNodeProps
...@@ -298,7 +294,7 @@ teamCpt :: R.Component SessionNodeProps ...@@ -298,7 +294,7 @@ teamCpt :: R.Component SessionNodeProps
teamCpt = here.component "team" cpt where teamCpt = here.component "team" cpt where
cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested { boxes, tasks } [ corpusLayout { nodeId, session } ] forested { boxes, tasks } [ corpusLayout { nodeId, session } ]
texts :: R2.Component SessionNodeProps texts :: R2.Component SessionNodeProps
...@@ -320,9 +316,8 @@ textsCpt = here.component "texts" cpt ...@@ -320,9 +316,8 @@ 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.textsWithForestSessionContext
Texts.textsWithForest
{ forestProps: { backend { forestProps: { backend
, forestOpen , forestOpen
, frontends , frontends
...@@ -335,8 +330,10 @@ textsCpt = here.component "texts" cpt ...@@ -335,8 +330,10 @@ textsCpt = here.component "texts" cpt
, tasks } , tasks }
, textsProps: { frontends , textsProps: { frontends
, nodeId , nodeId
, session: session' } } , session }
[] where frontends = defaultFrontends } []
where
frontends = defaultFrontends
user :: R2.Component SessionNodeProps user :: R2.Component SessionNodeProps
user = R.createElement userCpt user = R.createElement userCpt
...@@ -349,17 +346,14 @@ userCpt = here.component "user" cpt where ...@@ -349,17 +346,14 @@ userCpt = here.component "user" 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 $
R.useEffect' $ do
log2 "[user] session'" session'
pure $ authed sessionProps $ \_ ->
forested { boxes, tasks } forested { boxes, tasks }
[ userLayout { frontends [ userLayoutSessionContext { frontends
, nodeId , nodeId
, reloadForest , reloadForest
, reloadRoot , reloadRoot
, session: session' , session
, tasks } [] ] , tasks } [] ]
where frontends = defaultFrontends where frontends = defaultFrontends
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps ) type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
...@@ -373,7 +367,7 @@ contactCpt = here.component "contact" cpt where ...@@ -373,7 +367,7 @@ contactCpt = here.component "contact" cpt where
, boxes: { reloadForest, reloadRoot } } _ = do , boxes: { reloadForest, reloadRoot } } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
let forestedProps = RE.pick props :: Record Props let forestedProps = RE.pick props :: Record Props
pure $ authed sessionProps $ \_ -> pure $ authed sessionProps $
forested forestedProps forested forestedProps
[ contactLayout { annuaireId, frontends, nodeId, reloadForest, reloadRoot, session, tasks } [] ] [ contactLayout { annuaireId, frontends, nodeId, reloadForest, reloadRoot, session, tasks } [] ]
where frontends = defaultFrontends where frontends = defaultFrontends
...@@ -22,7 +22,6 @@ type Props = ...@@ -22,7 +22,6 @@ type Props =
( (
fallback :: R.Element fallback :: R.Element
, context :: R.Context Session , context :: R.Context Session
, render :: Unit -> Array R.Element
, sessionId :: SessionId , sessionId :: SessionId
, sessions :: T.Box Sessions , sessions :: T.Box Sessions
) )
...@@ -32,10 +31,10 @@ sessionWrapper = R.createElement sessionWrapperCpt ...@@ -32,10 +31,10 @@ sessionWrapper = R.createElement sessionWrapperCpt
sessionWrapperCpt :: R.Component Props sessionWrapperCpt :: R.Component Props
sessionWrapperCpt = here.component "sessionWrapper" cpt where sessionWrapperCpt = here.component "sessionWrapper" cpt where
cpt { fallback, context, render, sessionId, sessions } _ = do cpt { fallback, context, sessionId, sessions } content = do
sessions' <- T.useLive T.unequal sessions sessions' <- T.useLive T.unequal sessions
pure $ cp sessions' pure $ cp sessions'
where where
cp sessions' = c $ Sessions.lookup sessionId sessions' where cp sessions' = c $ Sessions.lookup sessionId sessions' where
c (Just session) = (R.provideContext context session (render unit)) c (Just session) = (R.provideContext context session content)
c Nothing = fallback c Nothing = fallback
-- | A module for authenticating to create sessions and handling them -- | A module for authenticating to create sessions and handling them
module Gargantext.Sessions module Gargantext.Sessions
( module Gargantext.Sessions.Types ( module Gargantext.Sessions.Types
, WithSession, WithSessionContext
, load, change , load, change
, Action(..), act, delete, get, post, put, put_ , Action(..), act, delete, get, post, put, put_
, postAuthRequest, deleteWithBody, postWwwUrlencoded , postAuthRequest, deleteWithBody, postWwwUrlencoded
...@@ -25,6 +26,10 @@ import Effect (Effect) ...@@ -25,6 +26,10 @@ import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Prelude import Prelude
( Unit, bind, otherwise, pure, unit, ($), (*>), (<$>), (<*), (>>=)) ( Unit, bind, otherwise, pure, unit, ($), (*>), (<$>), (<*), (>>=))
import Prim.Row (class Lacks, class Nub)
import Reactix as R
import Record as Record
import Record.Extra as REX
import Toestand as T import Toestand as T
import Web.Storage.Storage (getItem, removeItem, setItem) import Web.Storage.Storage (getItem, removeItem, setItem)
...@@ -35,6 +40,14 @@ import Gargantext.Config.REST as REST ...@@ -35,6 +40,14 @@ import Gargantext.Config.REST as REST
import Gargantext.Ends (class ToUrl, Backend, toUrl) import Gargantext.Ends (class ToUrl, Backend, toUrl)
import Gargantext.Utils.Reactix (getls) import Gargantext.Utils.Reactix (getls)
type WithSession c =
( session :: Session
| c )
type WithSessionContext c =
( session :: R.Context Session
| c )
load :: forall c. T.Write c Sessions => c -> Effect Sessions load :: forall c. T.Write c Sessions => c -> Effect Sessions
load cell = do load cell = do
sessions <- loadSessions sessions <- loadSessions
......
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