Router.purs 22.7 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 DOM.Simple as DOM
6
import Data.Array (filter, length)
7
import Data.Array as A
8
import Data.Foldable (intercalate)
Karen Konou's avatar
Karen Konou committed
9
import Data.Map as M
10
import Data.Maybe (Maybe(..), fromMaybe, maybe)
11 12 13
import Data.UUID (UUID)
import Data.UUID as UUID
import Effect (Effect)
arturo's avatar
arturo committed
14
import Gargantext.Components.App.Store (Boxes)
15
import Gargantext.Components.ErrorsView (errorsView)
arturo's avatar
arturo committed
16
import Gargantext.Components.Forest (forestLayout)
Karen Konou's avatar
Karen Konou committed
17
import Gargantext.Components.ForgotPassword (forgotPasswordLayout)
18
import Gargantext.Components.Login (login)
James Laver's avatar
James Laver committed
19
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
20
import Gargantext.Components.Nodes.Annuaire.User (userLayout)
James Laver's avatar
James Laver committed
21 22
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
import Gargantext.Components.Nodes.Corpus (corpusLayout)
23
import Gargantext.Components.Nodes.Corpus.Code (corpusCodeLayout)
James Laver's avatar
James Laver committed
24
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
arturo's avatar
arturo committed
25 26 27
import Gargantext.Components.Nodes.Corpus.Document as Document
import Gargantext.Components.Nodes.Corpus.Graph as Graph
import Gargantext.Components.Nodes.Corpus.Phylo as Phylo
James Laver's avatar
James Laver committed
28
import Gargantext.Components.Nodes.File (fileLayout)
arturo's avatar
arturo committed
29
import Gargantext.Components.Nodes.Frame as Frame
James Laver's avatar
James Laver committed
30 31 32
import Gargantext.Components.Nodes.Home (homeLayout)
import Gargantext.Components.Nodes.Lists as Lists
import Gargantext.Components.Nodes.Texts as Texts
33
import Gargantext.Components.Tile (tileBlock)
34
import Gargantext.Components.TopBar as TopBar
James Laver's avatar
James Laver committed
35
import Gargantext.Config (defaultFrontends, defaultBackends)
arturo's avatar
arturo committed
36
import Gargantext.Context.Session as SessionContext
James Laver's avatar
James Laver committed
37
import Gargantext.Ends (Backend)
arturo's avatar
arturo committed
38
import Gargantext.Hooks.Resize (ResizeType(..), useResizeHandler)
arturo's avatar
arturo committed
39
import Gargantext.Hooks.Session (useSession)
40
import Gargantext.Routes (AppRoute, Tile)
41
import Gargantext.Routes as GR
arturo's avatar
arturo committed
42
import Gargantext.Sessions (Session, sessionId)
43
import Gargantext.Sessions as Sessions
44
import Gargantext.Types (CorpusId, Handed(..), ListId, NodeID, NodeType(..), SessionId, SidePanelState(..))
arturo's avatar
arturo committed
45
import Gargantext.Utils ((?))
46
import Gargantext.Utils.Reactix (getElementById)
James Laver's avatar
James Laver committed
47
import Gargantext.Utils.Reactix as R2
48 49
import Reactix as R
import Reactix.DOM.HTML as H
50
import Record (get)
51 52 53
import Record as Record
import Record.Extra as RE
import Toestand as T
54
import Type.Proxy (Proxy(..))
James Laver's avatar
James Laver committed
55 56 57 58

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

59
type Props = ( boxes :: Boxes )
James Laver's avatar
James Laver committed
60

61
type SessionProps = ( sessionId :: SessionId | Props )
62

63
type SessionNodeProps = ( nodeId :: NodeID | SessionProps )
64
type Props' = ( backend :: Backend, route' :: AppRoute | Props )
65

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

74
    -- Computed
75
    let
76
      handedClassName :: Handed -> String
77 78 79 80
      handedClassName = case _ of
        LeftHanded  -> "left-handed"
        RightHanded -> "right-handed"

81 82 83 84 85 86 87 88 89 90 91 92 93 94
      toggleHandedClass :: Handed -> DOM.Element -> Effect Unit
      toggleHandedClass new el = do
        R2.removeClass el
          [ handedClassName LeftHanded
          , handedClassName RightHanded
          ]
        R2.addClass el
          [ handedClassName new
          ]

    -- Effects
    R.useLayoutEffect1' handed' do
      getElementById "app"    >>= maybe R.nothing (toggleHandedClass handed')
      getElementById "portal" >>= maybe R.nothing (toggleHandedClass handed')
95

96
    -- Render
arturo's avatar
arturo committed
97 98 99 100 101
    pure $

      H.div
      { className: "router" }
      [
102
        login' boxes
103
       , TopBar.topBar { boxes }
104
       , errorsView { errors: boxes.errors } []
arturo's avatar
arturo committed
105
       , H.div { className: "router__inner" }
arturo's avatar
arturo committed
106
         [
arturo's avatar
arturo committed
107
          forest { boxes }
arturo's avatar
arturo committed
108 109 110 111
         ,
          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
forest = R2.leaf forestCpt
arturo's avatar
arturo committed
212

arturo's avatar
arturo committed
213 214
forestCpt :: R.Memo Props
forestCpt = R.memo' $ here.component "forest" cpt where
arturo's avatar
arturo committed
215
  cpt { boxes } _ = do
arturo's avatar
arturo committed
216 217 218
    -- States
    showTree' <- R2.useLive' boxes.showTree

arturo's avatar
arturo committed
219 220 221 222
    -- Hooks
    resizeHandler <- useResizeHandler

    -- Effects
arturo's avatar
arturo committed
223
    R.useLayoutEffect1' [] do
arturo's avatar
arturo committed
224 225 226 227 228 229
      resizeHandler.add
        ".router__aside__handle__action"
        ".router__aside"
        Vertical
      pure $ resizeHandler.remove
        ".router__aside__handle__action"
arturo's avatar
arturo committed
230 231

    -- Render
232 233
    pure $

arturo's avatar
arturo committed
234
      H.div
arturo's avatar
arturo committed
235 236 237 238
      { className: "router__aside"
      -- @XXX: ReactJS lack of "keep-alive" feature workaround solution
      -- @link https://github.com/facebook/react/issues/12039
      , style: { display: showTree' ? "block" $ "none" }
arturo's avatar
arturo committed
239
      }
arturo's avatar
arturo committed
240
      [
arturo's avatar
arturo committed
241 242 243 244 245 246 247 248
        H.div
        { className: "router__aside__inner" }
        [
          forestLayout
          { boxes
          , frontends: defaultFrontends
          }
        ]
arturo's avatar
arturo committed
249 250
      ,
        H.div
arturo's avatar
arturo committed
251
        { className: "router__aside__handle"
arturo's avatar
arturo committed
252 253 254
        }
        [
          H.div
arturo's avatar
arturo committed
255
          { className: "router__aside__handle__action" }
arturo's avatar
arturo committed
256 257 258
          []
        ]
      ]
259

arturo's avatar
arturo committed
260 261
--------------------------------------------------------------

262
sidePanel :: R2.Leaf Props
263
sidePanel = R2.leafComponent sidePanelCpt
264
sidePanelCpt :: R.Component Props
265
sidePanelCpt = here.component "sidePanel" cpt where
266 267
  cpt props@{ boxes: { session
                     , sidePanelState } } _ = do
268
    session' <- T.useLive T.unequal session
269
    sidePanelState' <- T.useLive T.unequal sidePanelState
270

271 272
    case session' of
      Nothing -> pure $ H.div {} []
arturo's avatar
arturo committed
273
      Just _  ->
274
        case sidePanelState' of
arturo's avatar
arturo committed
275 276 277
          Opened -> pure $
            R.provideContext SessionContext.context session'
            [ openedSidePanel props ]
278
          _      -> pure $ H.div {} []
279

arturo's avatar
arturo committed
280 281
--------------------------------------------------------------

282 283 284 285 286 287
type RenderRouteProps =
  ( route :: AppRoute
  | Props
  )

renderRoute :: R2.Leaf RenderRouteProps
arturo's avatar
arturo committed
288 289 290 291
renderRoute = R2.leaf renderRouteCpt

renderRouteCpt :: R.Memo RenderRouteProps
renderRouteCpt = R.memo' $ here.component "renderRoute" cpt where
292 293 294 295 296 297
  cpt { boxes, route } _ = do
    let sessionNodeProps sId nId =
          { nodeId: nId
          , sessionId: sId
          , boxes
          }
298 299

    pure $ R.fragment
300
      [ case route of
301 302 303
        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) []
304
        GR.CorpusCode s n         -> corpusCode (sessionNodeProps s n) []
305 306 307 308 309 310 311 312 313 314 315
        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) []
316
        GR.PhyloExplorer s g      -> phyloExplorer (sessionNodeProps s g) []
317
        GR.RouteFile s n          -> routeFile (sessionNodeProps s n) []
318 319
        GR.RouteFrameWrite s n    -> routeFrame (Record.merge { nodeType: NodeFrameWrite    } $ sessionNodeProps s n) []
        GR.RouteFrameCalc  s n    -> routeFrame (Record.merge { nodeType: NodeFrameCalc     } $ sessionNodeProps s n) []
320
        GR.RouteFrameCode  s n    -> routeFrame (Record.merge { nodeType: NodeFrameNotebook } $ sessionNodeProps s n) []
321
        GR.RouteFrameVisio s n    -> routeFrame (Record.merge { nodeType: NodeFrameVisio    } $ sessionNodeProps s n) []
322
        GR.Team s n               -> team (sessionNodeProps s n) []
323
        GR.NodeTexts s n          -> texts (sessionNodeProps s n) []
324
        GR.UserPage s n           -> user (sessionNodeProps s n) []
Karen Konou's avatar
Karen Konou committed
325
        GR.ForgotPassword p       -> forgotPassword {boxes, params: p} []
326 327
      ]

arturo's avatar
arturo committed
328 329
--------------------------------------------------------------

330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
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
arturo's avatar
arturo committed
348 349
      Nothing -> pure $
        home homeProps []
arturo's avatar
arturo committed
350
      Just s -> pure $
arturo's avatar
arturo committed
351
        R.provideContext SessionContext.context session' [ content s ]
352 353 354
    where
      homeProps = RE.pick props :: Record Props

arturo's avatar
arturo committed
355 356
--------------------------------------------------------------

arturo's avatar
arturo committed
357 358 359 360
openedSidePanel :: R2.Leaf Props
openedSidePanel = R2.leaf openedSidePanelCpt

openedSidePanelCpt :: R.Component Props
361
openedSidePanelCpt = here.component "openedSidePanel" cpt where
arturo's avatar
arturo committed
362 363 364 365 366 367
  cpt { boxes:
        { route
        , sidePanelState
        }
      } _ = do
    session <- useSession
arturo's avatar
arturo committed
368

369
    route' <- T.useLive T.unequal route
370

371
    let wrapper = H.div { className: "side-panel" }
372

373
    case route' of
374
      GR.Lists _s _n -> do
375
        pure $ wrapper
376
          [ Lists.sidePanel { session
377
                            , sidePanelState } [] ]
arturo's avatar
arturo committed
378 379
      GR.NodeTexts _s _n ->
        pure $ wrapper [ Texts.textsSidePanel {} ]
380
      _ -> pure $ wrapper []
381

arturo's avatar
arturo committed
382 383
--------------------------------------------------------------

384 385 386
annuaire :: R2.Component SessionNodeProps
annuaire = R.createElement annuaireCpt
annuaireCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
387
annuaireCpt = here.component "annuaire" cpt where
388
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
389
    let sessionProps = RE.pick props :: Record SessionProps
390 391 392 393
    pure $ authed (Record.merge { content: \session ->
                                   annuaireLayout { frontends: defaultFrontends
                                                  , nodeId
                                                  , session } } sessionProps) []
394

arturo's avatar
arturo committed
395 396
--------------------------------------------------------------

397 398 399
corpus :: R2.Component SessionNodeProps
corpus = R.createElement corpusCpt
corpusCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
400
corpusCpt = here.component "corpus" cpt where
401
  cpt props@{ boxes, nodeId } _ = do
James Laver's avatar
James Laver committed
402
    let sessionProps = RE.pick props :: Record SessionProps
403
    pure $ authed (Record.merge { content: \session ->
404
                                   corpusLayout { boxes
405
                                                , nodeId
406
                                                , session } } sessionProps) []
407

arturo's avatar
arturo committed
408 409
--------------------------------------------------------------

410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
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
429 430
--------------------------------------------------------------

James Laver's avatar
James Laver committed
431 432
type CorpusDocumentProps =
  ( corpusId :: CorpusId
433
  , listId :: ListId
434 435 436 437 438
  | SessionNodeProps
  )

corpusDocument :: R2.Component CorpusDocumentProps
corpusDocument = R.createElement corpusDocumentCpt
arturo's avatar
arturo committed
439

440
corpusDocumentCpt :: R.Component CorpusDocumentProps
arturo's avatar
arturo committed
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
corpusDocumentCpt = here.component "corpusDocument" cpt where
  cpt props@{ corpusId, listId, nodeId } _ = do
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \session ->
              Document.node
              { mCorpusId: Just corpusId
              , listId
              , nodeId
              , key: show (sessionId session) <> "-" <> show nodeId
              }
        }
        sessionProps

    pure $ authed authedProps []
460

arturo's avatar
arturo committed
461 462
--------------------------------------------------------------

463 464 465 466 467
dashboard :: R2.Component SessionNodeProps
dashboard = R.createElement dashboardCpt
dashboardCpt :: R.Component SessionNodeProps
dashboardCpt = here.component "dashboard" cpt
  where
468
    cpt props@{ boxes, nodeId } _ = do
469
      let sessionProps = RE.pick props :: Record SessionProps
470
      pure $ authed (Record.merge { content: \session ->
471
                                     dashboardLayout { boxes, nodeId, session } [] } sessionProps) []
472

arturo's avatar
arturo committed
473 474
--------------------------------------------------------------

arturo's avatar
arturo committed
475 476 477 478
type DocumentProps =
  ( listId :: ListId
  | SessionNodeProps
  )
479 480 481

document :: R2.Component DocumentProps
document = R.createElement documentCpt
arturo's avatar
arturo committed
482

483
documentCpt :: R.Component DocumentProps
James Laver's avatar
James Laver committed
484
documentCpt = here.component "document" cpt where
485
  cpt props@{ listId, nodeId } _ = do
arturo's avatar
arturo committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \session ->
              Document.node
              { mCorpusId: Nothing
              , listId
              , nodeId
              , key: show (sessionId session) <> "-" <> show nodeId
              }
        }
        sessionProps

    pure $ authed authedProps []
503

arturo's avatar
arturo committed
504 505
--------------------------------------------------------------

506 507
graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt
arturo's avatar
arturo committed
508

509 510
graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where
arturo's avatar
arturo committed
511
  cpt props@{ nodeId } _ = do
512
    let
arturo's avatar
arturo committed
513
      sessionProps = (RE.pick props :: Record SessionProps)
514 515 516 517

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
518
            \_ -> Graph.node
arturo's avatar
arturo committed
519 520 521
                  { graphId: nodeId
                  , key: "graphId-" <> show nodeId
                  }
arturo's avatar
arturo committed
522

523 524 525 526 527
        }
        sessionProps

    pure $ authed authedProps []

arturo's avatar
arturo committed
528
--------------------------------------------------------------
529

530 531
phyloExplorer :: R2.Component SessionNodeProps
phyloExplorer = R.createElement phyloExplorerCpt
arturo's avatar
arturo committed
532

533
phyloExplorerCpt :: R.Component SessionNodeProps
534
phyloExplorerCpt = here.component "phylo" cpt where
arturo's avatar
arturo committed
535
  cpt props@{ nodeId } _ = do
536 537 538 539 540 541
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
542
            \_ -> Phylo.node
arturo's avatar
arturo committed
543 544
                  { nodeId
                  }
545 546
        }
        sessionProps
547

548
    pure $ authed authedProps []
549

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

552 553 554
home :: R2.Component Props
home = R.createElement homeCpt
homeCpt :: R.Component Props
James Laver's avatar
James Laver committed
555
homeCpt = here.component "home" cpt where
556
  cpt { boxes } _ = do
557
    pure $ homeLayout { boxes }
558

arturo's avatar
arturo committed
559 560
--------------------------------------------------------------

561 562 563
lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
564
listsCpt = here.component "lists" cpt where
565
  cpt props@{ boxes
566
            , nodeId } _ = do
James Laver's avatar
James Laver committed
567
    let sessionProps = RE.pick props :: Record SessionProps
568
    pure $ authed (Record.merge { content: \session ->
569
                                   Lists.listsLayout { boxes
570
                                                     , nodeId
571
                                                     , session
572
                                                     , sessionUpdate: \_ -> pure unit } [] } sessionProps) []
James Laver's avatar
James Laver committed
573

arturo's avatar
arturo committed
574 575
--------------------------------------------------------------

576
login' :: Boxes -> R.Element
James Laver's avatar
James Laver committed
577
login' { backend, sessions, showLogin: visible } =
arturo's avatar
arturo committed
578 579 580 581 582 583
  login
  { backend
  , backends: A.fromFoldable defaultBackends
  , sessions
  , visible
  }
James Laver's avatar
James Laver committed
584

arturo's avatar
arturo committed
585 586
--------------------------------------------------------------

587 588 589
routeFile :: R2.Component SessionNodeProps
routeFile = R.createElement routeFileCpt
routeFileCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
590
routeFileCpt = here.component "routeFile" cpt where
591
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
592
    let sessionProps = RE.pick props :: Record SessionProps
593 594
    pure $ authed (Record.merge { content: \session ->
                                   fileLayout { nodeId, session } } sessionProps) []
595

arturo's avatar
arturo committed
596 597
--------------------------------------------------------------

arturo's avatar
arturo committed
598 599
type RouteFrameProps =
  ( nodeType :: NodeType
600 601 602 603 604
  | SessionNodeProps
  )

routeFrame :: R2.Component RouteFrameProps
routeFrame = R.createElement routeFrameCpt
arturo's avatar
arturo committed
605

606
routeFrameCpt :: R.Component RouteFrameProps
James Laver's avatar
James Laver committed
607
routeFrameCpt = here.component "routeFrame" cpt where
608
  cpt props@{ nodeId, nodeType } _ = do
arturo's avatar
arturo committed
609 610 611 612 613 614 615
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \session ->
arturo's avatar
arturo committed
616
              Frame.node
arturo's avatar
arturo committed
617 618
              { nodeId
              , nodeType
arturo's avatar
arturo committed
619
              , key: show (sessionId session) <> "-" <> show nodeId
arturo's avatar
arturo committed
620 621 622 623 624 625
              }

        }
        sessionProps

    pure $ authed authedProps []
626

arturo's avatar
arturo committed
627 628
--------------------------------------------------------------

629 630 631
team :: R2.Component SessionNodeProps
team = R.createElement teamCpt
teamCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
632
teamCpt = here.component "team" cpt where
633
  cpt props@{ boxes, nodeId } _ = do
James Laver's avatar
James Laver committed
634
    let sessionProps = RE.pick props :: Record SessionProps
635
    pure $ authed (Record.merge { content: \session ->
636
                                   corpusLayout { boxes
637
                                                , nodeId
638
                                                , session } } sessionProps) []
639

arturo's avatar
arturo committed
640 641
--------------------------------------------------------------

642 643
texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt
arturo's avatar
arturo committed
644

645
textsCpt :: R.Component SessionNodeProps
arturo's avatar
arturo committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
textsCpt = here.component "texts" cpt where
  cpt props@{ nodeId } _ = do
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \_ -> Texts.textsLayout
                  { frontends: defaultFrontends
                  , nodeId
                  }
        }
        sessionProps

    pure $ authed authedProps []
662

arturo's avatar
arturo committed
663 664
--------------------------------------------------------------

665 666 667
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
668
userCpt = here.component "user" cpt where
669
  cpt props@{ boxes
670
            , nodeId } _ = do
James Laver's avatar
James Laver committed
671
    let sessionProps = RE.pick props :: Record SessionProps
672
    pure $ authed (Record.merge { content: \session ->
673
                                   userLayout { boxes
674
                                              , frontends: defaultFrontends
675
                                              , nodeId
676
                                              , session } [] } sessionProps) []
677

arturo's avatar
arturo committed
678 679
--------------------------------------------------------------

James Laver's avatar
James Laver committed
680
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
681 682 683 684

contact :: R2.Component ContactProps
contact = R.createElement contactCpt
contactCpt :: R.Component ContactProps
James Laver's avatar
James Laver committed
685
contactCpt = here.component "contact" cpt where
686
  cpt props@{ annuaireId
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
            , nodeId
            } _ = do
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        { content:
            \_ -> contactLayout
                  { nodeId
                  , annuaireId
                  , key: "annuaireId-" <> show annuaireId
                  }
        } `Record.merge` sessionProps

    pure $ authed authedProps []
Karen Konou's avatar
Karen Konou committed
702 703 704 705 706 707 708 709 710 711 712 713 714

--------------------------------------------------------------

type ForgotPasswordProps = ( params :: (M.Map String String) | Props)

forgotPassword :: R2.Component ForgotPasswordProps
forgotPassword = R.createElement forgotPasswordCpt

forgotPasswordCpt :: R.Component ForgotPasswordProps
forgotPasswordCpt = here.component "forgotPassword" cpt where
  cpt { params } _ = do
    let server = fromMaybe "" $ M.lookup "server" params
    let uuid = fromMaybe "" $ M.lookup "uuid" params
715

Karen Konou's avatar
Karen Konou committed
716
    pure $ forgotPasswordLayout { server, uuid } []