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