Router.purs 22.3 KB
Newer Older
James Laver's avatar
James Laver committed
1 2
module Gargantext.Components.Router (router) where

3 4
import Gargantext.Prelude

5
import Data.Array (filter, length)
6
import Data.Array as A
7
import Data.Foldable (intercalate)
James Laver's avatar
James Laver committed
8
import Data.Maybe (Maybe(..))
9 10 11
import Data.UUID (UUID)
import Data.UUID as UUID
import Effect (Effect)
12
import Gargantext.Components.App.Data (Boxes)
13
import Gargantext.Components.ErrorsView (errorsView)
James Laver's avatar
James Laver committed
14
import Gargantext.Components.Footer (footer)
arturo's avatar
arturo committed
15
import Gargantext.Components.Forest (forestLayout)
James Laver's avatar
James Laver committed
16 17
import Gargantext.Components.Login (login)
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
18
import Gargantext.Components.Nodes.Annuaire.User (userLayout)
James Laver's avatar
James Laver committed
19 20
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
import Gargantext.Components.Nodes.Corpus (corpusLayout)
21
import Gargantext.Components.Nodes.Corpus.Code (corpusCodeLayout)
James Laver's avatar
James Laver committed
22 23
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
import Gargantext.Components.Nodes.Corpus.Document (documentMainLayout)
arturo's avatar
arturo committed
24 25
import Gargantext.Components.Nodes.Corpus.Graph (graphLayout)
import Gargantext.Components.Nodes.Corpus.Phylo (phyloLayout)
James Laver's avatar
James Laver committed
26 27 28 29 30
import Gargantext.Components.Nodes.File (fileLayout)
import Gargantext.Components.Nodes.Frame (frameLayout)
import Gargantext.Components.Nodes.Home (homeLayout)
import Gargantext.Components.Nodes.Lists as Lists
import Gargantext.Components.Nodes.Texts as Texts
31
import Gargantext.Components.Tile (tileBlock)
32
import Gargantext.Components.TopBar as TopBar
James Laver's avatar
James Laver committed
33
import Gargantext.Config (defaultFrontends, defaultBackends)
James Laver's avatar
James Laver committed
34
import Gargantext.Ends (Backend)
arturo's avatar
arturo committed
35 36
import Gargantext.Hooks.FirstEffect (useFirstEffect)
import Gargantext.Hooks.Resize (ResizeType(..), useResizeHandler)
37
import Gargantext.Routes (AppRoute, Tile)
38
import Gargantext.Routes as GR
39
import Gargantext.Sessions (Session, WithSession)
40
import Gargantext.Sessions as Sessions
41 42
import Gargantext.Types (CorpusId, Handed(..), ListId, NodeID, NodeType(..), SessionId, SidePanelState(..))
import Gargantext.Utils.Reactix (getElementById)
James Laver's avatar
James Laver committed
43
import Gargantext.Utils.Reactix as R2
44 45
import Reactix as R
import Reactix.DOM.HTML as H
46
import Record (get)
47 48 49
import Record as Record
import Record.Extra as RE
import Toestand as T
50
import Type.Proxy (Proxy(..))
James Laver's avatar
James Laver committed
51 52 53 54

here :: R2.Here
here = R2.here "Gargantext.Components.Router"

55
type Props = ( boxes :: Boxes )
James Laver's avatar
James Laver committed
56

57
type SessionProps = ( sessionId :: SessionId | Props )
58

59
type SessionNodeProps = ( nodeId :: NodeID | SessionProps )
60
type Props' = ( backend :: Backend, route' :: AppRoute | Props )
61

James Laver's avatar
James Laver committed
62
router :: R2.Leaf Props
63
router = R2.leafComponent routerCpt
James Laver's avatar
James Laver committed
64
routerCpt :: R.Component Props
65
routerCpt = here.component "router" cpt where
arturo's avatar
arturo committed
66
  cpt { boxes: boxes@{ handed, showLogin, showTree } } _ = do
67
    -- States
arturo's avatar
arturo committed
68 69 70
    handed'     <- R2.useLive' handed
    showLogin'  <- R2.useLive' showLogin
    showTree'   <- R2.useLive' showTree
71

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    -- Effects
    let
      handedClassName = case _ of
        LeftHanded  -> "left-handed"
        RightHanded -> "right-handed"

    R.useEffect1' handed' $
      getElementById "app" >>= case _ of
        Nothing  -> pure unit
        Just app -> do
          R2.removeClass app
            [ handedClassName LeftHanded
            , handedClassName RightHanded
            ]
          R2.addClass app [ handedClassName handed' ]
87

88
    -- Render
arturo's avatar
arturo committed
89 90 91 92 93 94 95 96
    pure $

      H.div
      { className: "router" }
      [
        -- loginModal { boxes }
         R2.if' showLogin' $
            login' boxes
97
       , TopBar.topBar { boxes }
98
       , errorsView { errors: boxes.errors } []
arturo's avatar
arturo committed
99
       , H.div { className: "router__inner" }
arturo's avatar
arturo committed
100 101 102 103 104 105 106 107 108 109 110 111
         [
          -- @XXX: ReactJS lack of "keep-alive" feature workaround solution
          -- @link https://github.com/facebook/react/issues/12039
          --   ↓
          -- @XXX: ReactJS "display: none" don't exec effect cleaning function
          --       (therefore cannot use the simple "display: none" workaround
          --       to keep below component alive)
          R2.if' (showTree') $ forest { boxes }
         ,
          mainPage { boxes }
         ,
          sidePanel { boxes }
112
         ]
113
       ]
114

arturo's avatar
arturo committed
115
--------------------------------------------------------------
116

117
mainPage :: R2.Leaf Props
118
mainPage = R2.leafComponent mainPageCpt
119 120 121
mainPageCpt :: R.Component Props
mainPageCpt = here.component "mainPage" cpt where
  cpt { boxes } _ = do
122 123 124 125 126 127 128 129 130
    -- States
    route         <- R2.useLive' boxes.route
    tileAxisXList <- R2.useLive' boxes.tileAxisXList
    tileAxisYList <- R2.useLive' boxes.tileAxisYList
    -- Computed
    let
      findTile :: UUID -> Record Tile -> Boolean
      findTile id tile = eq id $ get (Proxy :: Proxy "id") tile

arturo's avatar
arturo committed
131 132 133 134
      deleteTile ::
           Record Tile
        -> T.Box (Array (Record Tile))
        -> (Unit -> Effect Unit)
135 136 137 138 139 140 141 142 143 144
      deleteTile tile listBox = const do
        list <- T.read listBox
        newList <- pure $ filter (_ # tile.id # findTile # not) list
        T.write_ newList listBox

    let hasHorizontalTiles = not $ eq 0 $ length tileAxisXList
    let hasVerticalTiles = not $ eq 0 $ length tileAxisYList
    -- Render
    pure $

arturo's avatar
arturo committed
145
      H.div { className: "router__body main-page" }
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
      [
        H.div
        { className: intercalate " "
          [ "main-page__main-row"
          , if (hasVerticalTiles)
            then "main-page__main-row--with-y-tiles"
            else ""
          , if (hasVerticalTiles && not hasHorizontalTiles)
            then "main-page__main-row--only-y-tiles"
            else ""
          ]
        }
        [
          -- main render route
          H.div { className: "main-page__main-route" }
          [
            renderRoute { boxes, route }
          ]
        ,
          -- optional tile render route [Y Axis ~ aside vertical column]
          case tileAxisYList of
            [] -> mempty
            _  ->
              H.div
              { className: intercalate " "
                [ "main-page__vertical-tiles"
                , "main-page__vertical-tiles--" <> (show $ length tileAxisYList)
                ]
              } $
              tileAxisYList <#> \tile -> tileBlock
                { boxes
                , tile
                , key: UUID.toString tile.id
                , closeCallback: deleteTile tile boxes.tileAxisYList
                }
                [
                  renderRoute { boxes, route: tile.route }
                ]
        ]

      ,
        -- optional tile render route [X Axis ~ bottom horizontal row]
        case tileAxisXList of
          [] -> mempty
          _  ->
            H.div
            { className: intercalate " "
              [ "main-page__horizontal-tiles"
              , "main-page__horizontal-tiles--" <> (show $ length tileAxisXList)
              ]
            } $
            tileAxisXList <#> \tile -> tileBlock
              { boxes
              , tile
              , key: UUID.toString tile.id
              , closeCallback: deleteTile tile boxes.tileAxisXList
              }
              [
                renderRoute { boxes, route: tile.route }
              ]
      ]

arturo's avatar
arturo committed
208
--------------------------------------------------------------
209

210
forest :: R2.Leaf Props
arturo's avatar
arturo committed
211 212 213
forest = R2.leaf forestCpt
forestCpt :: R.Memo Props
forestCpt = R.memo' $ here.component "forest" cpt where
arturo's avatar
arturo committed
214
  cpt { boxes } _ = do
arturo's avatar
arturo committed
215 216 217 218 219 220 221 222 223
    -- Hooks
    resizeHandler <- useResizeHandler

    -- Effects
    useFirstEffect do
      resizeHandler.add ".router__handle__action" ".router__aside" Vertical
      pure $ resizeHandler.remove ".router__handle__action"

    -- Render
224 225
    pure $

arturo's avatar
arturo committed
226
      H.div
arturo's avatar
arturo committed
227
      { className: "router__aside" }
arturo's avatar
arturo committed
228
      [
arturo's avatar
arturo committed
229
        forestLayout
arturo's avatar
arturo committed
230 231 232 233 234 235 236 237 238 239 240 241 242
        { boxes
        , frontends: defaultFrontends
        }
      ,
        H.div
        { className: "router__handle"
        }
        [
          H.div
          { className: "router__handle__action" }
          []
        ]
      ]
243

arturo's avatar
arturo committed
244 245
--------------------------------------------------------------

246
sidePanel :: R2.Leaf Props
247
sidePanel = R2.leafComponent sidePanelCpt
248
sidePanelCpt :: R.Component Props
249
sidePanelCpt = here.component "sidePanel" cpt where
250 251
  cpt props@{ boxes: { session
                     , sidePanelState } } _ = do
252
    session' <- T.useLive T.unequal session
253
    sidePanelState' <- T.useLive T.unequal sidePanelState
254

255 256 257 258 259 260
    case session' of
      Nothing -> pure $ H.div {} []
      Just s  ->
        case sidePanelState' of
          Opened -> pure $ openedSidePanel (Record.merge { session: s } props) []
          _      -> pure $ H.div {} []
261

arturo's avatar
arturo committed
262 263
--------------------------------------------------------------

264 265 266 267 268 269
type RenderRouteProps =
  ( route :: AppRoute
  | Props
  )

renderRoute :: R2.Leaf RenderRouteProps
270
renderRoute = R2.leafComponent renderRouteCpt
271
renderRouteCpt :: R.Component RenderRouteProps
272
renderRouteCpt = here.component "renderRoute" cpt where
273 274 275 276 277 278
  cpt { boxes, route } _ = do
    let sessionNodeProps sId nId =
          { nodeId: nId
          , sessionId: sId
          , boxes
          }
279 280

    pure $ R.fragment
281
      [ case route of
282 283 284
        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) []
285
        GR.CorpusCode s n         -> corpusCode (sessionNodeProps s n) []
286 287 288 289 290 291 292 293 294 295 296
        GR.CorpusDocument s c l n -> corpusDocument (Record.merge { corpusId: c, listId: l } $ sessionNodeProps s n) []
        GR.Dashboard s n          -> dashboard (sessionNodeProps s n) []
        GR.Document s l n         -> document (Record.merge { listId: l } $ sessionNodeProps s n) []
        GR.Folder        s n      -> corpus (sessionNodeProps s n) []
        GR.FolderPrivate s n      -> corpus (sessionNodeProps s n) []
        GR.FolderPublic  s n      -> corpus (sessionNodeProps s n) []
        GR.FolderShared  s n      -> corpus (sessionNodeProps s n) []
        GR.Home                   -> home { boxes } []
        GR.Lists s n              -> lists (sessionNodeProps s n) []
        GR.Login                  -> login' boxes
        GR.PGraphExplorer s g     -> graphExplorer (sessionNodeProps s g) []
297
        GR.PhyloExplorer s g      -> phyloExplorer (sessionNodeProps s g) []
298
        GR.RouteFile s n          -> routeFile (sessionNodeProps s n) []
299 300
        GR.RouteFrameWrite s n    -> routeFrame (Record.merge { nodeType: NodeFrameWrite    } $ sessionNodeProps s n) []
        GR.RouteFrameCalc  s n    -> routeFrame (Record.merge { nodeType: NodeFrameCalc     } $ sessionNodeProps s n) []
301
        GR.RouteFrameCode  s n    -> routeFrame (Record.merge { nodeType: NodeFrameNotebook } $ sessionNodeProps s n) []
302
        GR.RouteFrameVisio s n    -> routeFrame (Record.merge { nodeType: NodeFrameVisio    } $ sessionNodeProps s n) []
303
        GR.Team s n               -> team (sessionNodeProps s n) []
304
        GR.NodeTexts s n          -> texts (sessionNodeProps s n) []
305 306 307
        GR.UserPage s n           -> user (sessionNodeProps s n) []
      ]

arturo's avatar
arturo committed
308 309
--------------------------------------------------------------

310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
type AuthedProps =
  ( content :: Session -> R.Element
  | SessionProps )

authed :: R2.Component AuthedProps
authed = R.createElement authedCpt
authedCpt :: R.Component AuthedProps
authedCpt = here.component "authed" cpt where
  cpt props@{ boxes: { session, sessions }
            , content
            , sessionId } _ = do
    sessions' <- T.useLive T.unequal sessions
    let session' = Sessions.lookup sessionId sessions'

    R.useEffect' $ do
      T.write_ session' session

    case session' of
      Nothing -> pure $ home homeProps []
      Just s  -> pure $ R.fragment [ content s, footer {} [] ]
    where
      homeProps = RE.pick props :: Record Props

arturo's avatar
arturo committed
333 334
--------------------------------------------------------------

335
openedSidePanel :: R2.Component (WithSession Props)
336
openedSidePanel = R.createElement openedSidePanelCpt
337
openedSidePanelCpt :: R.Component (WithSession Props)
338
openedSidePanelCpt = here.component "openedSidePanel" cpt where
339 340 341 342
  cpt { boxes: boxes@{ route
                     , sidePanelState
                     , sidePanelTexts }
      , session } _ = do
arturo's avatar
arturo committed
343

344
    route' <- T.useLive T.unequal route
345

346
    let wrapper = H.div { className: "side-panel" }
347

348
    case route' of
349
      GR.Lists _s _n -> do
350
        pure $ wrapper
351
          [ Lists.sidePanel { session
352
                            , sidePanelState } [] ]
353
      GR.NodeTexts _s _n -> do
354
        pure $ wrapper
355 356 357
          [ Texts.textsSidePanel { boxes
                                 , session
                                 , sidePanel: sidePanelTexts } [] ]
358
      _ -> pure $ wrapper []
359

arturo's avatar
arturo committed
360 361
--------------------------------------------------------------

362 363 364
annuaire :: R2.Component SessionNodeProps
annuaire = R.createElement annuaireCpt
annuaireCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
365
annuaireCpt = here.component "annuaire" cpt where
366
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
367
    let sessionProps = RE.pick props :: Record SessionProps
368 369 370 371
    pure $ authed (Record.merge { content: \session ->
                                   annuaireLayout { frontends: defaultFrontends
                                                  , nodeId
                                                  , session } } sessionProps) []
372

arturo's avatar
arturo committed
373 374
--------------------------------------------------------------

375 376 377
corpus :: R2.Component SessionNodeProps
corpus = R.createElement corpusCpt
corpusCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
378
corpusCpt = here.component "corpus" cpt where
379
  cpt props@{ boxes, nodeId } _ = do
James Laver's avatar
James Laver committed
380
    let sessionProps = RE.pick props :: Record SessionProps
381
    pure $ authed (Record.merge { content: \session ->
382
                                   corpusLayout { boxes
383
                                                , nodeId
384
                                                , session } } sessionProps) []
385

arturo's avatar
arturo committed
386 387
--------------------------------------------------------------

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
corpusCode :: R2.Component SessionNodeProps
corpusCode = R.createElement corpusCodeCpt
corpusCodeCpt :: R.Component SessionNodeProps
corpusCodeCpt = here.component "corpusCode" cpt where
  cpt props@{ boxes, nodeId } _ = do
    let
      sessionProps = RE.pick props :: Record SessionProps

      authedProps = Record.merge
        { content: \session -> corpusCodeLayout
            { nodeId
            , session
            , boxes
            }
        }
        sessionProps

    pure $ authed authedProps []

arturo's avatar
arturo committed
407 408
--------------------------------------------------------------

James Laver's avatar
James Laver committed
409 410
type CorpusDocumentProps =
  ( corpusId :: CorpusId
411
  , listId :: ListId
412 413 414 415 416 417 418 419
  | SessionNodeProps
  )

corpusDocument :: R2.Component CorpusDocumentProps
corpusDocument = R.createElement corpusDocumentCpt
corpusDocumentCpt :: R.Component CorpusDocumentProps
corpusDocumentCpt = here.component "corpusDocument" cpt
  where
420
    cpt props@{ corpusId: corpusId', listId, nodeId } _ = do
421
      let sessionProps = RE.pick props :: Record SessionProps
422
      pure $ authed (Record.merge { content: \session ->
423 424 425 426
                                     documentMainLayout { mCorpusId: Just corpusId'
                                                        , listId: listId
                                                        , nodeId
                                                        , session } [] } sessionProps )[]
427

arturo's avatar
arturo committed
428 429
--------------------------------------------------------------

430 431 432 433 434
dashboard :: R2.Component SessionNodeProps
dashboard = R.createElement dashboardCpt
dashboardCpt :: R.Component SessionNodeProps
dashboardCpt = here.component "dashboard" cpt
  where
435
    cpt props@{ boxes, nodeId } _ = do
436
      let sessionProps = RE.pick props :: Record SessionProps
437
      pure $ authed (Record.merge { content: \session ->
438
                                     dashboardLayout { boxes, nodeId, session } [] } sessionProps) []
439

arturo's avatar
arturo committed
440 441
--------------------------------------------------------------

James Laver's avatar
James Laver committed
442
type DocumentProps = ( listId :: ListId | SessionNodeProps )
443 444 445 446

document :: R2.Component DocumentProps
document = R.createElement documentCpt
documentCpt :: R.Component DocumentProps
James Laver's avatar
James Laver committed
447
documentCpt = here.component "document" cpt where
448
  cpt props@{ listId, nodeId } _ = do
James Laver's avatar
James Laver committed
449
    let sessionProps = RE.pick props :: Record SessionProps
450
    pure $ authed (Record.merge { content: \session ->
451 452 453 454
                                   documentMainLayout { listId
                                                      , nodeId
                                                      , mCorpusId: Nothing
                                                      , session } [] } sessionProps) []
455

arturo's avatar
arturo committed
456 457
--------------------------------------------------------------

458 459 460 461
graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt
graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where
462
  cpt props@{ boxes
463
            , nodeId } _ = do
464 465 466 467 468 469
    let
      sessionProps = RE.pick props :: Record SessionProps

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
470
            \session -> graphLayout
471 472 473
                        { boxes
                        , graphId: nodeId
                        , key: "graphId-" <> show nodeId
arturo's avatar
arturo committed
474 475 476
                        , session
                        }

477 478 479 480 481
        }
        sessionProps

    pure $ authed authedProps []

arturo's avatar
arturo committed
482
--------------------------------------------------------------
483

484 485 486
phyloExplorer :: R2.Component SessionNodeProps
phyloExplorer = R.createElement phyloExplorerCpt
phyloExplorerCpt :: R.Component SessionNodeProps
487 488 489 490 491 492 493 494 495
phyloExplorerCpt = here.component "phylo" cpt where
  cpt props@{ boxes
            , nodeId } _ = do
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
496
            \session -> phyloLayout
497 498 499 500 501 502
                        { boxes
                        , nodeId
                        , session
                        }
        }
        sessionProps
503

504
    pure $ authed authedProps []
505

arturo's avatar
arturo committed
506
--------------------------------------------------------------
507

508 509 510
home :: R2.Component Props
home = R.createElement homeCpt
homeCpt :: R.Component Props
James Laver's avatar
James Laver committed
511
homeCpt = here.component "home" cpt where
512
  cpt { boxes } _ = do
513
    pure $ homeLayout { boxes }
514

arturo's avatar
arturo committed
515 516
--------------------------------------------------------------

517 518 519
lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
520
listsCpt = here.component "lists" cpt where
521
  cpt props@{ boxes
522
            , nodeId } _ = do
James Laver's avatar
James Laver committed
523
    let sessionProps = RE.pick props :: Record SessionProps
524
    pure $ authed (Record.merge { content: \session ->
525
                                   Lists.listsLayout { boxes
526
                                                     , nodeId
527
                                                     , session
528
                                                     , sessionUpdate: \_ -> pure unit } [] } sessionProps) []
James Laver's avatar
James Laver committed
529

arturo's avatar
arturo committed
530 531
--------------------------------------------------------------

532
login' :: Boxes -> R.Element
James Laver's avatar
James Laver committed
533
login' { backend, sessions, showLogin: visible } =
534
  login { backend
535
        , backends: A.fromFoldable defaultBackends
536 537
        , sessions
        , visible }
James Laver's avatar
James Laver committed
538

arturo's avatar
arturo committed
539 540
--------------------------------------------------------------

541 542 543
routeFile :: R2.Component SessionNodeProps
routeFile = R.createElement routeFileCpt
routeFileCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
544
routeFileCpt = here.component "routeFile" cpt where
545
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
546
    let sessionProps = RE.pick props :: Record SessionProps
547 548
    pure $ authed (Record.merge { content: \session ->
                                   fileLayout { nodeId, session } } sessionProps) []
549

arturo's avatar
arturo committed
550 551
--------------------------------------------------------------

552 553 554 555 556 557 558 559
type RouteFrameProps = (
  nodeType :: NodeType
  | SessionNodeProps
  )

routeFrame :: R2.Component RouteFrameProps
routeFrame = R.createElement routeFrameCpt
routeFrameCpt :: R.Component RouteFrameProps
James Laver's avatar
James Laver committed
560
routeFrameCpt = here.component "routeFrame" cpt where
561
  cpt props@{ nodeId, nodeType } _ = do
James Laver's avatar
James Laver committed
562
    let sessionProps = RE.pick props :: Record SessionProps
563 564
    pure $ authed (Record.merge { content: \session ->
                                   frameLayout { nodeId, nodeType, session } } sessionProps) []
565

arturo's avatar
arturo committed
566 567
--------------------------------------------------------------

568 569 570
team :: R2.Component SessionNodeProps
team = R.createElement teamCpt
teamCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
571
teamCpt = here.component "team" cpt where
572
  cpt props@{ boxes, nodeId } _ = do
James Laver's avatar
James Laver committed
573
    let sessionProps = RE.pick props :: Record SessionProps
574
    pure $ authed (Record.merge { content: \session ->
575
                                   corpusLayout { boxes
576
                                                , nodeId
577
                                                , session } } sessionProps) []
578

arturo's avatar
arturo committed
579 580
--------------------------------------------------------------

581 582 583 584 585
texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt
textsCpt :: R.Component SessionNodeProps
textsCpt = here.component "texts" cpt
  where
586
    cpt props@{ boxes
587
              , nodeId } _ = do
588
      let sessionProps = RE.pick props :: Record SessionProps
589
      pure $ authed (Record.merge { content: \session ->
590
                                     Texts.textsLayout { boxes
591
                                                       , frontends: defaultFrontends
592
                                                       , nodeId
593
                                                       , session } [] } sessionProps) []
594

arturo's avatar
arturo committed
595 596
--------------------------------------------------------------

597 598 599
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
600
userCpt = here.component "user" cpt where
601
  cpt props@{ boxes
602
            , nodeId } _ = do
James Laver's avatar
James Laver committed
603
    let sessionProps = RE.pick props :: Record SessionProps
604
    pure $ authed (Record.merge { content: \session ->
605
                                   userLayout { boxes
606
                                              , frontends: defaultFrontends
607
                                              , nodeId
608
                                              , session } [] } sessionProps) []
609

arturo's avatar
arturo committed
610 611
--------------------------------------------------------------

James Laver's avatar
James Laver committed
612
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
613 614 615 616

contact :: R2.Component ContactProps
contact = R.createElement contactCpt
contactCpt :: R.Component ContactProps
James Laver's avatar
James Laver committed
617
contactCpt = here.component "contact" cpt where
618
  cpt props@{ annuaireId
619
            , boxes
620
            , nodeId } _ = do
James Laver's avatar
James Laver committed
621
    let sessionProps = RE.pick props :: Record SessionProps
622
    -- let forestedProps = RE.pick props :: Record Props
623 624
    pure $ authed (Record.merge { content: \session ->
                                   contactLayout { annuaireId
625
                                                 , boxes
626 627
                                                 , frontends: defaultFrontends
                                                 , nodeId
628
                                                 , session } [] } sessionProps) []