Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
purescript-gargantext
Commits
217a2f36
Commit
217a2f36
authored
Mar 11, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[toestand] fixes to session context props for components
parent
e5eabd49
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
47 deletions
+112
-47
User.purs
src/Gargantext/Components/Nodes/Annuaire/User.purs
+20
-3
Lists.purs
src/Gargantext/Components/Nodes/Lists.purs
+24
-3
Texts.purs
src/Gargantext/Components/Nodes/Texts.purs
+24
-3
Router.purs
src/Gargantext/Components/Router.purs
+29
-35
SessionLoader.purs
src/Gargantext/Components/SessionLoader.purs
+2
-3
Sessions.purs
src/Gargantext/Sessions.purs
+13
-0
No files found.
src/Gargantext/Components/Nodes/Annuaire/User.purs
View file @
217a2f36
module Gargantext.Components.Nodes.Annuaire.User
( module Gargantext.Components.Nodes.Annuaire.User.Contacts.Types
, userLayout
, userLayoutSessionContext
)
where
...
...
@@ -13,6 +14,8 @@ import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Record.Extra as REX
import Toestand as T
import Gargantext.AsyncTasks as GAT
...
...
@@ -23,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types as LT
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader)
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.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
...
...
@@ -147,20 +150,34 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
listElement :: Array R.Element -> R.Element
listElement = H.li { className: "list-group-item justify-content-between" }
type LayoutProps =
type Layout
NoSession
Props =
( frontends :: Frontends
, nodeId :: Int
, reloadForest :: T.Box T2.Reload
, reloadRoot :: T.Box T2.Reload
, session :: Session
, tasks :: T.Box (Maybe GAT.Reductor)
)
type LayoutProps = WithSession LayoutNoSessionProps
type LayoutSessionContextProps = WithSessionContext LayoutNoSessionProps
type KeyLayoutProps = (
key :: String
| 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 = R.createElement userLayoutCpt
...
...
src/Gargantext/Components/Nodes/Lists.purs
View file @
217a2f36
...
...
@@ -9,6 +9,7 @@ import Effect.Aff (launchAff_)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Record.Extra as REX
import Toestand as T
import Gargantext.AsyncTasks as GAT
...
...
@@ -25,7 +26,7 @@ import Gargantext.Components.Nodes.Lists.Types
import Gargantext.Components.Table as Table
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.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
...
...
@@ -38,6 +39,23 @@ type ListsWithForest =
, 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 = R.createElement listsWithForestCpt
...
...
@@ -67,15 +85,18 @@ topBarCpt = here.component "topBar" cpt where
-- ]
-- ] -- head (goes to top bar)
type CommonProps =
type CommonProps
NoSession
=
( nodeId :: Int
, reloadForest :: T.Box T2.Reload
, reloadRoot :: T.Box T2.Reload
, session :: Session
, sessionUpdate :: Session -> Effect Unit
, tasks :: T.Box (Maybe GAT.Reductor)
)
type CommonProps = WithSession CommonPropsNoSession
type CommonPropsSessionContext = WithSessionContext CommonPropsNoSession
type Props = ( controls :: Record ListsLayoutControls | CommonProps )
type WithTreeProps = ( handed :: GT.Handed | Props )
...
...
src/Gargantext/Components/Nodes/Texts.purs
View file @
217a2f36
...
...
@@ -13,6 +13,7 @@ import Effect.Aff (launchAff_)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Record.Extra as REX
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.Forest as Forest
...
...
@@ -32,7 +33,7 @@ import Gargantext.Components.Nodes.Texts.Types
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table
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.Utils.Reactix as R2
...
...
@@ -45,6 +46,24 @@ type TextsWithForest = (
, 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 = R.createElement textsWithForestCpt
...
...
@@ -80,12 +99,14 @@ topBarCpt = here.component "topBar" cpt
type CommonProps = (
type CommonProps
NoSession
= (
frontends :: Frontends
, nodeId :: NodeID
, session :: Session
)
type CommonProps = WithSession CommonPropsNoSession
type CommonPropsSessionContext = WithSessionContext CommonPropsNoSession
type Props = ( controls :: Record TextsLayoutControls | CommonProps )
textsLayout :: R2.Component Props
...
...
src/Gargantext/Components/Router.purs
View file @
217a2f36
...
...
@@ -2,7 +2,6 @@ module Gargantext.Components.Router (router) where
import Data.Array (fromFoldable)
import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log2)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
...
...
@@ -20,7 +19,7 @@ import Gargantext.Components.GraphExplorer (explorerLayoutLoader)
import Gargantext.Components.Lang (LandingLang(LL_EN))
import Gargantext.Components.Login (login)
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
import Gargantext.Components.Nodes.Annuaire.User (userLayout)
import Gargantext.Components.Nodes.Annuaire.User (userLayout
SessionContext
)
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
import Gargantext.Components.Nodes.Corpus (corpusLayout)
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
...
...
@@ -112,15 +111,13 @@ forestedCpt = here.component "forested" cpt
, showLogin
, 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 =
sessionWrapper { fallback: home homeProps []
, context: session
, render
, sessionId
, sessions } []
, sessions } [
content, footer {} []
]
where
render _ = [ content unit, footer {} [] ]
homeProps = RE.pick props :: Record Props
annuaire :: R2.Component SessionNodeProps
...
...
@@ -130,7 +127,7 @@ annuaireCpt :: R.Component SessionNodeProps
annuaireCpt = here.component "annuaire" cpt where
cpt props@{ boxes, nodeId, session, sessionId, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ annuaireLayout { frontends, nodeId, session } ]
where frontends = defaultFrontends
...
...
@@ -141,7 +138,7 @@ corpusCpt :: R.Component SessionNodeProps
corpusCpt = here.component "corpus" cpt where
cpt props@{ boxes, nodeId, session, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ corpusLayout { nodeId, session } ]
type CorpusDocumentProps =
...
...
@@ -158,7 +155,7 @@ corpusDocumentCpt = here.component "corpusDocument" cpt
where
cpt props@{ boxes, corpusId: corpusId', listId, nodeId, session, sessionId, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks }
[ documentMainLayout { mCorpusId: corpusId, listId: listId, nodeId, session } [] ]
where corpusId = Just corpusId'
...
...
@@ -171,7 +168,7 @@ dashboardCpt = here.component "dashboard" cpt
where
cpt props@{ boxes, nodeId, session, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ dashboardLayout { nodeId, session } [] ]
type DocumentProps = ( listId :: ListId | SessionNodeProps )
...
...
@@ -183,7 +180,7 @@ documentCpt :: R.Component DocumentProps
documentCpt = here.component "document" cpt where
cpt props@{ listId, nodeId, session, sessionId, tasks, boxes } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks }
[ documentMainLayout { listId, nodeId, mCorpusId, session } [] ]
where mCorpusId = Nothing
...
...
@@ -214,9 +211,8 @@ listsCpt = here.component "lists" cpt where
, sessionId
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
pure $ authed sessionProps $ \_ ->
Lists.listsWithForest
pure $ authed sessionProps $
Lists.listsWithForestSessionContext
{ forestProps: { backend
, forestOpen
, frontends
...
...
@@ -230,7 +226,7 @@ listsCpt = here.component "lists" cpt where
, listsProps: { nodeId
, reloadRoot
, reloadForest
, session
: session'
, session
, sessionUpdate: \_ -> pure unit
, tasks }
} []
...
...
@@ -253,7 +249,7 @@ graphExplorerCpt = here.component "graphExplorer" cpt where
, session
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
simpleLayout { handed }
[ explorerLayoutLoader { backend
, frontends
...
...
@@ -273,7 +269,7 @@ routeFileCpt :: R.Component SessionNodeProps
routeFileCpt = here.component "routeFile" cpt where
cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ fileLayout { nodeId, session } ]
type RouteFrameProps = (
...
...
@@ -288,7 +284,7 @@ routeFrameCpt :: R.Component RouteFrameProps
routeFrameCpt = here.component "routeFrame" cpt where
cpt props@{ nodeId, nodeType, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ frameLayout { nodeId, nodeType, session } ]
team :: R2.Component SessionNodeProps
...
...
@@ -298,7 +294,7 @@ teamCpt :: R.Component SessionNodeProps
teamCpt = here.component "team" cpt where
cpt props@{ nodeId, session, sessionId, boxes, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested { boxes, tasks } [ corpusLayout { nodeId, session } ]
texts :: R2.Component SessionNodeProps
...
...
@@ -320,9 +316,8 @@ textsCpt = here.component "texts" cpt
, sessionId
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
pure $ authed sessionProps $ \_ ->
Texts.textsWithForest
pure $ authed sessionProps $
Texts.textsWithForestSessionContext
{ forestProps: { backend
, forestOpen
, frontends
...
...
@@ -335,8 +330,10 @@ textsCpt = here.component "texts" cpt
, tasks }
, textsProps: { frontends
, nodeId
, session: session' } }
[] where frontends = defaultFrontends
, session }
} []
where
frontends = defaultFrontends
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
...
...
@@ -349,17 +346,14 @@ userCpt = here.component "user" cpt where
, sessionId
, tasks } _ = do
let sessionProps = RE.pick props :: Record SessionProps
session' <- R.useContext session
R.useEffect' $ do
log2 "[user] session'" session'
pure $ authed sessionProps $ \_ ->
pure $ authed sessionProps $
forested { boxes, tasks }
[ userLayout { frontends
, nodeId
, reloadForest
, reloadRoot
, session: session'
, tasks } [] ]
[ userLayout
SessionContext
{ frontends
, nodeId
, reloadForest
, reloadRoot
, session
, tasks } [] ]
where frontends = defaultFrontends
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
...
...
@@ -373,7 +367,7 @@ contactCpt = here.component "contact" cpt where
, boxes: { reloadForest, reloadRoot } } _ = do
let sessionProps = RE.pick props :: Record SessionProps
let forestedProps = RE.pick props :: Record Props
pure $ authed sessionProps $
\_ ->
pure $ authed sessionProps $
forested forestedProps
[ contactLayout { annuaireId, frontends, nodeId, reloadForest, reloadRoot, session, tasks } [] ]
where frontends = defaultFrontends
src/Gargantext/Components/SessionLoader.purs
View file @
217a2f36
...
...
@@ -22,7 +22,6 @@ type Props =
(
fallback :: R.Element
, context :: R.Context Session
, render :: Unit -> Array R.Element
, sessionId :: SessionId
, sessions :: T.Box Sessions
)
...
...
@@ -32,10 +31,10 @@ sessionWrapper = R.createElement sessionWrapperCpt
sessionWrapperCpt :: R.Component Props
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
pure $ cp 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
src/Gargantext/Sessions.purs
View file @
217a2f36
-- | A module for authenticating to create sessions and handling them
module Gargantext.Sessions
( module Gargantext.Sessions.Types
, WithSession, WithSessionContext
, load, change
, Action(..), act, delete, get, post, put, put_
, postAuthRequest, deleteWithBody, postWwwUrlencoded
...
...
@@ -25,6 +26,10 @@ import Effect (Effect)
import Effect.Aff (Aff)
import Prelude
( 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 Web.Storage.Storage (getItem, removeItem, setItem)
...
...
@@ -35,6 +40,14 @@ import Gargantext.Config.REST as REST
import Gargantext.Ends (class ToUrl, Backend, toUrl)
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 cell = do
sessions <- loadSessions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment