Commit e984d3dc authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[router] refactoring of sessions (no more context)

parent b27a7f6e
......@@ -11,7 +11,7 @@ import Gargantext.Components.Nodes.Texts.Types as TextsT
import Gargantext.Ends (Backend)
import Gargantext.Routes (AppRoute(Home))
import Gargantext.Sessions as Sessions
import Gargantext.Sessions (OpenNodes, Sessions)
import Gargantext.Sessions (OpenNodes, Session, Sessions)
import Gargantext.Types (Handed(RightHanded), SidePanelState(..))
import Gargantext.Utils.Toestand as T2
......@@ -24,6 +24,7 @@ type App =
, reloadMainPage :: T2.Reload
, reloadRoot :: T2.Reload
, route :: AppRoute
, session :: Maybe Session
, sessions :: Sessions
, showCorpus :: Boolean
, showLogin :: Boolean
......@@ -45,6 +46,7 @@ emptyApp =
, reloadMainPage : T2.newReload
, reloadRoot : T2.newReload
, route : Home
, session : Nothing
, sessions : Sessions.empty
, showCorpus : false
, showLogin : false
......@@ -65,6 +67,7 @@ type Boxes =
, reloadMainPage :: T2.ReloadS
, reloadRoot :: T2.ReloadS
, route :: T.Box AppRoute
, session :: T.Box (Maybe Session)
, sessions :: T.Box Sessions
, showCorpus :: T.Box Boolean
, showLogin :: T.Box Boolean
......
......@@ -379,18 +379,19 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
, totalRecords }
, localCategories
, params } _ = do
reload <- T.useBox T2.newReload
localCategories' <- T.useLive T.unequal localCategories
sidePanel' <- T.useLive T.unequal sidePanel
let mCurrentDocId = maybe Nothing (_.mCurrentDocId) sidePanel'
mCurrentDocId <- T.useFocused
(maybe Nothing _.mCurrentDocId)
(\val -> maybe Nothing (\sp -> Just $ sp { mCurrentDocId = val })) sidePanel
mCurrentDocId' <- T.useLive T.unequal mCurrentDocId
pure $ TT.table
{ colNames
, container: TT.defaultContainer { title: "Documents" }
, params
, rows: rows reload localCategories' mCurrentDocId
, rows: rows reload localCategories' mCurrentDocId'
, syncResetButton : [ H.div {} [] ]
, totalRecords
, wrapColElts
......@@ -407,7 +408,7 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
| otherwise = Routes.Document sid listId
colNames = TT.ColumnName <$> [ "Show", "Tag", "Date", "Title", "Source", "Score" ]
wrapColElts = const identity
rows reload localCategories' mCurrentDocId = row <$> A.toUnfoldable documents
rows reload localCategories' mCurrentDocId' = row <$> A.toUnfoldable documents
where
row dv@(DocumentsView r@{ _id, category }) =
{ row:
......@@ -444,7 +445,7 @@ pagePaintRawCpt = here.component "pagePaintRawCpt" cpt where
-- checked = Star_1 == cat
tClassName = trashClassName cat selected
className = gi cat
selected = mCurrentDocId == Just r._id
selected = mCurrentDocId' == Just r._id
type DocChooser = (
listId :: ListId
......
......@@ -52,7 +52,6 @@ type Props =
type TreeExtra = (
forestOpen :: T.Box OpenNodes
, session :: Session
)
forest :: R2.Component Props
......
......@@ -55,8 +55,6 @@ type BaseProps =
, tasks :: T.Box GAT.Storage
)
type LayoutLoaderProps = ( session :: R.Context Session | BaseProps )
type LayoutProps =
( session :: Session
| BaseProps )
......@@ -75,17 +73,6 @@ type Props =
)
--------------------------------------------------------------
explorerLayoutLoader :: R2.Component LayoutLoaderProps
explorerLayoutLoader = R.createElement explorerLayoutLoaderCpt
explorerLayoutLoaderCpt :: R.Component LayoutLoaderProps
explorerLayoutLoaderCpt = here.component "explorerLayoutLoader" cpt where
cpt props _ = do
session <- R.useContext props.session -- TODO: ugh, props fiddling
let base = RX.pick props :: Record BaseProps
let props' = Record.merge base { session }
pure $ explorerLayout props' []
explorerLayout :: R2.Component LayoutProps
explorerLayout = R.createElement explorerLayoutCpt
......
......@@ -49,7 +49,7 @@ newtype IndividuView =
type LayoutProps =
( frontends :: Frontends
, nodeId :: Int
, session :: R.Context Session
, session :: Session
)
annuaireLayout :: R2.Leaf LayoutProps
......@@ -57,15 +57,14 @@ annuaireLayout props = R.createElement annuaireLayoutCpt props []
annuaireLayoutCpt :: R.Component LayoutProps
annuaireLayoutCpt = here.component "annuaireLayout" cpt where
cpt { frontends, nodeId, session } _ = cp <$> R.useContext session where
cp s = annuaireLayoutWithKey { frontends, key, nodeId, session: s } where
key = show (sessionId s) <> "-" <> show nodeId
cpt { frontends, nodeId, session } _ = do
pure $ annuaireLayoutWithKey { frontends, key, nodeId, session }
where
key = show (sessionId session) <> "-" <> show nodeId
type KeyLayoutProps =
( frontends :: Frontends
, nodeId :: Int
, session :: Session
, key :: String
( key :: String
| LayoutProps
)
annuaireLayoutWithKey :: R2.Leaf KeyLayoutProps
......
module Gargantext.Components.Nodes.Annuaire.User
( module Gargantext.Components.Nodes.Annuaire.User.Contacts.Types
, userLayout
, userLayoutSessionContext
)
where
......@@ -170,17 +169,6 @@ type KeyLayoutProps = (
| 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
......
......@@ -160,7 +160,7 @@ type KeyLayoutProps = ( key :: String, session :: Session | ReloadProps )
saveContactHyperdata :: Session -> Int -> HyperdataContact -> Aff Int
saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "")
type AnnuaireLayoutProps = ( annuaireId :: Int, session :: R.Context Session | ReloadProps )
type AnnuaireLayoutProps = ( annuaireId :: Int, session :: Session | ReloadProps )
type AnnuaireKeyLayoutProps = ( annuaireId :: Int | KeyLayoutProps )
......@@ -178,8 +178,7 @@ contactLayoutCpt = here.component "contactLayout" cpt where
, sidePanel
, sidePanelState
, tasks } _ = do
s <- R.useContext session
let key = show (sessionId s) <> "-" <> show nodeId
let key = show (sessionId session) <> "-" <> show nodeId
pure $
contactLayoutWithKey
{ annuaireId
......@@ -188,7 +187,7 @@ contactLayoutCpt = here.component "contactLayout" cpt where
, nodeId
, reloadForest
, reloadRoot
, session: s
, session
, sidePanel
, sidePanelState
, tasks
......
module Gargantext.Components.Nodes.Corpus where
import Gargantext.Prelude (class Eq, class Show, Unit, bind, discard, pure, show, unit, ($), (+), (-), (<), (<$>), (<<<), (<>), (==), (>))
import DOM.Simple.Console (log2)
import Data.Argonaut (class DecodeJson, decodeJson, encodeJson)
import Data.Argonaut.Parser (jsonParser)
import Data.Array as A
......@@ -11,46 +11,44 @@ import Data.Generic.Rep.Show (genericShow)
import Data.List as List
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (Tuple(..))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.FolderView as FV
import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.FolderView as FV
import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (doc)
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Nodes.Types
( FTField, FTFieldWithIndex, FTFieldsWithIndex, Field(..), FieldType(..), Hash, Index
, defaultField, defaultHaskell', defaultJSON', defaultMarkdown', defaultPython' )
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..))
import Gargantext.Components.Nodes.Types (FTField, FTFieldWithIndex, FTFieldsWithIndex, Field(..), FieldType(..), Hash, Index, defaultField, defaultHaskell', defaultJSON', defaultMarkdown', defaultPython')
import Gargantext.Data.Array as GDA
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (class Eq, class Show, Unit, bind, discard, pure, show, unit, ($), (+), (-), (<), (<$>), (<<<), (<>), (==), (>))
import Gargantext.Routes (SessionRoute(Children, NodeAPI))
import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (AffTableResult, NodeType(..))
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus"
type Props = ( nodeId :: Int, session :: R.Context Session )
type Props = ( nodeId :: Int, session :: Session )
corpusLayout :: R2.Leaf Props
corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayoutCpt :: R.Component Props
corpusLayoutCpt = here.component "corpusLayout" cpt where
cpt { nodeId, session } _ = cp <$> R.useContext session where
cp s = corpusLayoutMain { key, nodeId, session: s } where
key = show (sessionId s) <> "-" <> show nodeId
cpt { nodeId, session } _ = do
pure $ corpusLayoutMain { key, nodeId, session }
where
key = show (sessionId session) <> "-" <> show nodeId
type KeyProps =
( nodeId :: Int
......
......@@ -28,21 +28,21 @@ import Gargantext.Utils.Toestand as T2
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Dashboard"
type Props = ( nodeId :: NodeID, session :: R.Context Session )
type Props = ( nodeId :: NodeID, session :: Session )
dashboardLayout :: R2.Component Props
dashboardLayout = R.createElement dashboardLayoutCpt
dashboardLayoutCpt :: R.Component Props
dashboardLayoutCpt = here.component "dashboardLayout" cpt where
cpt { nodeId, session } content = cp <$> R.useContext session where
cp s = dashboardLayoutWithKey { key, nodeId, session: s } content where
key = show (sessionId s) <> "-" <> show nodeId
cpt { nodeId, session } content = do
pure $ dashboardLayoutWithKey { key, nodeId, session } content
where
key = show (sessionId session) <> "-" <> show nodeId
type KeyProps =
( key :: String
, nodeId :: NodeID
, session :: Session
| Props
)
dashboardLayoutWithKey :: R2.Component KeyProps
......
......@@ -118,7 +118,7 @@ type LayoutProps =
( listId :: ListId
, mCorpusId :: Maybe NodeID
, nodeId :: NodeID
, session :: R.Context Session
, session :: Session
)
documentMainLayout :: R2.Component LayoutProps
......@@ -133,9 +133,10 @@ documentLayout = R.createElement documentLayoutCpt
documentLayoutCpt :: R.Component LayoutProps
documentLayoutCpt = here.component "documentLayout" cpt where
cpt { listId, mCorpusId, nodeId, session } children = cp <$> R.useContext session where
cp s = documentLayoutWithKey { key, listId, mCorpusId, nodeId, session: s } children where
key = show (sessionId s) <> "-" <> show nodeId
cpt { listId, mCorpusId, nodeId, session } children = do
pure $ documentLayoutWithKey { key, listId, mCorpusId, nodeId, session } children
where
key = show (sessionId session) <> "-" <> show nodeId
type KeyLayoutProps =
( key :: String
......
......@@ -55,25 +55,25 @@ instance decodeFile :: DecodeJson File where
hyperdata <- (obj .: "hyperdata") >>= decodeJson
pure $ File { id, date, hyperdata, name }
type FileLayoutProps = ( nodeId :: NodeID, session :: R.Context Session )
type FileLayoutProps = ( nodeId :: NodeID, session :: Session )
fileLayout :: R2.Leaf FileLayoutProps
fileLayout props = R.createElement fileLayoutCpt props []
fileLayoutCpt :: R.Component FileLayoutProps
fileLayoutCpt = here.component "fileLayout" cpt where
cpt { nodeId, session } _ = R.useContext session >>= cp where
cp s = useLoader nodeId (loadFile s) onLoad where
onLoad loaded = fileLayoutLoaded { loaded, nodeId, session: s } where
key = show (sessionId s) <> "-" <> show nodeId
cpt { nodeId, session } _ = do
useLoader nodeId (loadFile session) onLoad
where
onLoad loaded = fileLayoutLoaded { loaded, nodeId, session }
key = show (sessionId session) <> "-" <> show nodeId
loadFile :: Session -> NodeID -> Aff File
loadFile session nodeId = get session $ NodeAPI Node (Just nodeId) ""
type FileLayoutLoadedProps =
( loaded :: File
, nodeId :: Int
, session :: Session
| FileLayoutProps
)
fileLayoutLoaded :: Record FileLayoutLoadedProps -> R.Element
......
......@@ -46,15 +46,13 @@ instance encodeJsonHyperdata :: Argonaut.EncodeJson Hyperdata where
type Props =
( nodeId :: Int
, session :: R.Context Session
, nodeType :: NodeType
, session :: Session
)
type KeyProps =
( key :: String
, nodeId :: Int
, session :: Session
, nodeType :: NodeType
| Props
)
frameLayout :: R2.Leaf Props
......@@ -62,9 +60,10 @@ frameLayout props = R.createElement frameLayoutCpt props []
frameLayoutCpt :: R.Component Props
frameLayoutCpt = here.component "frameLayout" cpt where
cpt { nodeId, nodeType, session } _ = cp <$> R.useContext session where
cp s = frameLayoutWithKey { key, nodeId, nodeType, session: s } where
key = show (sessionId s) <> "-" <> show nodeId
cpt { nodeId, nodeType, session } _ = do
pure $ frameLayoutWithKey { key, nodeId, nodeType, session }
where
key = show (sessionId session) <> "-" <> show nodeId
frameLayoutWithKey :: R2.Leaf KeyProps
frameLayoutWithKey props = R.createElement frameLayoutWithKeyCpt props []
......
......@@ -24,16 +24,6 @@ import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Lists"
listsWithSessionContext :: R2.Component CommonPropsSessionContext
listsWithSessionContext = R.createElement listsWithSessionContextCpt
listsWithSessionContextCpt :: R.Component CommonPropsSessionContext
listsWithSessionContextCpt = here.component "listsWithSessionContext" cpt where
cpt props@{ session, sidePanel, sidePanelState } _ = do
session' <- R.useContext session
pure $ listsLayout (Record.merge { session: session', sidePanel, sidePanelState } props) []
--------------------------------------------------------
type CommonPropsNoSession =
......
......@@ -33,20 +33,6 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Texts"
--------------------------------------------------------
textsWithSessionContext :: R2.Component CommonPropsSessionContext
textsWithSessionContext = R.createElement textsWithSessionContextCpt
textsWithSessionContextCpt :: R.Component CommonPropsSessionContext
textsWithSessionContextCpt = here.component "textsWithSessionContext" cpt
where
cpt props@{ session, sidePanel, sidePanelState } _ = do
session' <- R.useContext session
pure $ R.fragment
[
textsLayout (Record.merge { session: session', sidePanel, sidePanelState } props) []
-- , H.div { className: "side-panel" } [ sidePanelC { session: session', sidePanel } [] ]
]
type CommonPropsNoSession = (
......@@ -57,7 +43,6 @@ type CommonPropsNoSession = (
)
type Props = WithSession CommonPropsNoSession
type CommonPropsSessionContext = WithSessionContext CommonPropsNoSession
textsLayout :: R2.Component Props
......@@ -427,9 +412,7 @@ sidePanelDocViewCpt = here.component "sidePanelDocView" cpt
pure $ H.div {} []
cpt { mSidePanel: Just { corpusId, listId, nodeId }
, session } _ = do
let session' = R.createContext session
pure $ D.documentLayout { listId
, mCorpusId: Just corpusId
, nodeId
, session: session' } []
, session } []
This diff is collapsed.
......@@ -20,8 +20,8 @@ here = R2.here "Gargantext.Components.SessionWrapper"
type Props =
(
fallback :: R.Element
, context :: R.Context Session
context :: R.Context Session
, fallback :: R.Element
, sessionId :: SessionId
, sessions :: T.Box Sessions
)
......
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