Commit 0f030aae authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

Merge branch 'feature/toestand-global-state' of...

Merge branch 'feature/toestand-global-state' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into feature/toestand-global-state
parents db7e16cc cd5c85f2
......@@ -4,7 +4,7 @@ import Data.Set as Set
import Data.Maybe (Maybe(..))
import Toestand as T
import Gargantext.Ends (Backend(..))
import Gargantext.Ends (Backend)
import Gargantext.Sessions as Sessions
import Gargantext.Sessions (OpenNodes, Sessions)
import Gargantext.Routes (AppRoute(Home))
......@@ -12,7 +12,8 @@ import Gargantext.Types (Handed(RightHanded))
import Gargantext.Utils.Toestand as T2
type App =
{ handed :: Handed
{ backend :: Maybe Backend
, handed :: Handed
, forestOpen :: OpenNodes
, reloadRoot :: Int
, reloadForest :: Int
......@@ -24,7 +25,8 @@ type App =
emptyApp :: App
emptyApp =
{ handed: RightHanded
{ backend: Nothing
, handed: RightHanded
, route: Home
, forestOpen: Set.empty
, reloadRoot: T2.newReload
......
......@@ -11,7 +11,7 @@ module Gargantext.Components.Forest
import Data.Array as A
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Set as Set
import Data.Tuple (fst, snd)
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import Reactix as R
import Reactix.DOM.HTML as H
......@@ -25,7 +25,7 @@ import Gargantext.Ends (Frontends, Backend)
import Gargantext.Prelude
import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (Session(..), Sessions, OpenNodes, unSessions)
import Gargantext.Types (Handed(..), reverseHanded, switchHanded)
import Gargantext.Types (Handed, reverseHanded, switchHanded)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
......@@ -74,8 +74,7 @@ forestCpt = here.component "forest" cpt where
, showLogin
, tasks } _ = do
tasks' <- GAT.useTasks reloadRoot reloadForest
R.useEffect' $ do
T2.write_ (Just tasks') tasks
R.useEffect' $ T2.write_ (Just tasks') tasks
handed' <- T.useLive T.unequal handed
reloadForest' <- T.useLive T.unequal reloadForest
reloadRoot' <- T.useLive T.unequal reloadRoot
......@@ -95,7 +94,7 @@ forestCpt = here.component "forest" cpt where
common = RX.pick props :: Record Common
cp handed' sessions' tasks' _ =
pure $ H.div { className: "forest" }
(A.cons (plus handed' showLogin) (trees handed' sessions' tasks'))
(A.cons (plus handed' showLogin backend) (trees handed' sessions' tasks'))
trees handed' sessions' tasks' = (tree handed' tasks') <$> unSessions sessions'
tree handed' tasks' s@(Session {treeId}) =
treeLoader { forestOpen
......@@ -108,8 +107,8 @@ forestCpt = here.component "forest" cpt where
, session: s
, tasks } []
plus :: Handed -> T.Cursor Boolean -> R.Element
plus handed showLogin = H.div { className: "row" }
plus :: Handed -> T.Cursor Boolean -> T.Cursor (Maybe Backend) -> R.Element
plus handed showLogin backend = H.div { className: "row" }
[ H.button { className: buttonClass
, on: { click }
, title }
......@@ -122,7 +121,7 @@ plus handed showLogin = H.div { className: "row" }
-- [ H.i { className: "material-icons md-36"} [] ]
where
click _ = do
-- _ <- T.modify (const Nothing) backend
-- _ <- T.write Nothing backend
T2.write_ true showLogin
title = "Add or remove connections to the server(s)."
divClass = "fa fa-universal-access"
......
......@@ -32,6 +32,7 @@ import Gargantext.Components.Nodes.Texts as Texts
import Gargantext.Components.SessionLoader (sessionWrapper)
import Gargantext.Components.SimpleLayout (simpleLayout)
import Gargantext.Config (defaultFrontends, defaultBackends, publicBackend)
import Gargantext.Ends (Backend)
import Gargantext.Routes (AppRoute(..))
import Gargantext.Routes as GR
import Gargantext.Sessions (Session)
......@@ -57,6 +58,7 @@ type SessionNodeProps = (
nodeId :: NodeID
| SessionProps
)
type Props' = ( route' :: AppRoute, backend :: Backend | Props )
router :: R2.Leaf Props
router props = R.createElement routerCpt props []
......@@ -68,9 +70,10 @@ routerCpt = here.component "root" cpt where
let sessionProps sId = Record.merge { session, sessionId: sId } props
let sessionNodeProps sId nId = Record.merge { nodeId: nId } $ sessionProps sId
showLogin <- T.useLive T.unequal cursors.showLogin
route <- T.useLive (T.changed notEq) cursors.route
route' <- T.useLive (T.changed notEq) cursors.route
let props' = Record.merge props { route' }
if showLogin then login' cursors
else case route of
else case route' of
GR.Annuaire s n -> annuaire (sessionNodeProps s n) []
GR.ContactPage s a n -> contact (Record.merge { annuaireId: a } $ sessionNodeProps s n)
GR.Corpus s n -> corpus (sessionNodeProps s n)
......
......@@ -4,10 +4,12 @@
module Gargantext.Components.SessionLoader
where
import Prelude (($), (<$>))
import Data.Maybe (Maybe(..))
import Reactix as R
import Toestand as T
import Gargantext.Prelude
import Gargantext.Sessions as Sessions
import Gargantext.Sessions (Session, Sessions)
import Gargantext.Types (SessionId)
......@@ -16,21 +18,23 @@ import Gargantext.Utils.Reactix as R2
here :: R2.Here
here = R2.here "Gargantext.Components.SessionWrapper"
type Props sessions =
type Props =
(
fallback :: R.Element
, provider :: R.Provider Session
, sessionId :: SessionId
, sessions :: sessions
, sessions :: T.Cursor Sessions
)
sessionWrapper :: forall s. T.Read s Sessions => R2.Component (Props s)
sessionWrapper :: R2.Component Props
sessionWrapper = R.createElement sessionWrapperCpt
sessionWrapperCpt :: forall s. T.Read s Sessions => R.Component (Props s)
sessionWrapperCpt :: R.Component Props
sessionWrapperCpt = here.component "sessionWrapper" cpt where
cpt { fallback, provider, sessionId, sessions } content =
cp <$> T.useLive T.unequal sessions where
cpt { fallback, provider, 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.provide provider session content)
c Nothing = fallback
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