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 as 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
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
arturo's avatar
arturo committed
22
import Gargantext.Components.Nodes.Corpus as Corpus
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
import Gargantext.Components.Nodes.Corpus.Document as Document
import Gargantext.Components.Nodes.Corpus.Phylo as Phylo
27
import Gargantext.Components.Nodes.Graph as Graph
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.leaf 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 104 105 106 107 108 109 110 111 112
      ,
        TopBar.component
        {}
      ,
        ErrorsView.component
        {}
      ,
        H.div
        { className: "router__inner" }
        [
arturo's avatar
arturo committed
113
          forest { boxes }
114
        ,
arturo's avatar
arturo committed
115
          mainPage { boxes }
116
        ,
arturo's avatar
arturo committed
117
          sidePanel { boxes }
118 119
        ]
      ]
120

arturo's avatar
arturo committed
121
--------------------------------------------------------------
122

123
mainPage :: R2.Leaf Props
124
mainPage = R2.leaf mainPageCpt
125 126 127
mainPageCpt :: R.Component Props
mainPageCpt = here.component "mainPage" cpt where
  cpt { boxes } _ = do
128 129 130 131 132 133 134 135 136
    -- 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
137 138 139 140
      deleteTile ::
           Record Tile
        -> T.Box (Array (Record Tile))
        -> (Unit -> Effect Unit)
141 142
      deleteTile tile listBox = const do
        list <- T.read listBox
143
        newList <- pure $ filter (not $ findTile $ tile.id) list
144 145 146 147 148 149 150
        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
151
      H.div { className: "router__body main-page" }
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 208 209 210 211 212 213
      [
        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
214
--------------------------------------------------------------
215

216
forest :: R2.Leaf Props
arturo's avatar
arturo committed
217
forest = R2.leaf forestCpt
arturo's avatar
arturo committed
218

arturo's avatar
arturo committed
219 220
forestCpt :: R.Memo Props
forestCpt = R.memo' $ here.component "forest" cpt where
arturo's avatar
arturo committed
221
  cpt { boxes } _ = do
arturo's avatar
arturo committed
222 223 224
    -- States
    showTree' <- R2.useLive' boxes.showTree

arturo's avatar
arturo committed
225 226 227 228
    -- Hooks
    resizeHandler <- useResizeHandler

    -- Effects
arturo's avatar
arturo committed
229
    R.useLayoutEffect1' [] do
arturo's avatar
arturo committed
230 231 232 233 234 235
      resizeHandler.add
        ".router__aside__handle__action"
        ".router__aside"
        Vertical
      pure $ resizeHandler.remove
        ".router__aside__handle__action"
arturo's avatar
arturo committed
236 237

    -- Render
238 239
    pure $

arturo's avatar
arturo committed
240
      H.div
arturo's avatar
arturo committed
241 242 243 244
      { 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
245
      }
arturo's avatar
arturo committed
246
      [
arturo's avatar
arturo committed
247 248 249 250 251 252 253 254
        H.div
        { className: "router__aside__inner" }
        [
          forestLayout
          { boxes
          , frontends: defaultFrontends
          }
        ]
arturo's avatar
arturo committed
255 256
      ,
        H.div
arturo's avatar
arturo committed
257
        { className: "router__aside__handle"
arturo's avatar
arturo committed
258 259 260
        }
        [
          H.div
arturo's avatar
arturo committed
261
          { className: "router__aside__handle__action" }
arturo's avatar
arturo committed
262 263 264
          []
        ]
      ]
265

arturo's avatar
arturo committed
266 267
--------------------------------------------------------------

268
sidePanel :: R2.Leaf Props
269
sidePanel = R2.leaf sidePanelCpt
270
sidePanelCpt :: R.Component Props
271
sidePanelCpt = here.component "sidePanel" cpt where
272 273
  cpt props@{ boxes: { session
                     , sidePanelState } } _ = do
274
    session' <- T.useLive T.unequal session
275
    sidePanelState' <- T.useLive T.unequal sidePanelState
276

277 278
    case session' of
      Nothing -> pure $ H.div {} []
arturo's avatar
arturo committed
279
      Just _  ->
280
        case sidePanelState' of
arturo's avatar
arturo committed
281 282 283
          Opened -> pure $
            R.provideContext SessionContext.context session'
            [ openedSidePanel props ]
284
          _      -> pure $ H.div {} []
285

arturo's avatar
arturo committed
286 287
--------------------------------------------------------------

288 289 290 291 292 293
type RenderRouteProps =
  ( route :: AppRoute
  | Props
  )

renderRoute :: R2.Leaf RenderRouteProps
arturo's avatar
arturo committed
294 295 296 297
renderRoute = R2.leaf renderRouteCpt

renderRouteCpt :: R.Memo RenderRouteProps
renderRouteCpt = R.memo' $ here.component "renderRoute" cpt where
298 299 300 301 302 303
  cpt { boxes, route } _ = do
    let sessionNodeProps sId nId =
          { nodeId: nId
          , sessionId: sId
          , boxes
          }
304 305

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

arturo's avatar
arturo committed
334 335
--------------------------------------------------------------

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

arturo's avatar
arturo committed
361 362
--------------------------------------------------------------

arturo's avatar
arturo committed
363 364 365 366
openedSidePanel :: R2.Leaf Props
openedSidePanel = R2.leaf openedSidePanelCpt

openedSidePanelCpt :: R.Component Props
367
openedSidePanelCpt = here.component "openedSidePanel" cpt where
arturo's avatar
arturo committed
368 369 370 371 372 373
  cpt { boxes:
        { route
        , sidePanelState
        }
      } _ = do
    session <- useSession
arturo's avatar
arturo committed
374

375
    route' <- T.useLive T.unequal route
376

377
    let wrapper = H.div { className: "side-panel" }
378

379
    case route' of
380
      GR.Lists _s _n -> do
381
        pure $ wrapper
382
          [ Lists.sidePanel { session
383
                            , sidePanelState } [] ]
arturo's avatar
arturo committed
384 385
      GR.NodeTexts _s _n ->
        pure $ wrapper [ Texts.textsSidePanel {} ]
386
      _ -> pure $ wrapper []
387

arturo's avatar
arturo committed
388 389
--------------------------------------------------------------

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

arturo's avatar
arturo committed
401 402
--------------------------------------------------------------

403 404 405
corpus :: R2.Component SessionNodeProps
corpus = R.createElement corpusCpt
corpusCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
406
corpusCpt = here.component "corpus" cpt where
arturo's avatar
arturo committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  cpt props@{ nodeId } _ = do
    let
      sessionProps = RE.pick props :: Record SessionProps

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

    pure $ authed authedProps []
422

arturo's avatar
arturo committed
423 424
--------------------------------------------------------------

425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
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
444 445
--------------------------------------------------------------

James Laver's avatar
James Laver committed
446 447
type CorpusDocumentProps =
  ( corpusId :: CorpusId
448
  , listId :: ListId
449 450 451 452 453
  | SessionNodeProps
  )

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

455
corpusDocumentCpt :: R.Component CorpusDocumentProps
arturo's avatar
arturo committed
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
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 []
475

arturo's avatar
arturo committed
476 477
--------------------------------------------------------------

478 479 480 481 482
dashboard :: R2.Component SessionNodeProps
dashboard = R.createElement dashboardCpt
dashboardCpt :: R.Component SessionNodeProps
dashboardCpt = here.component "dashboard" cpt
  where
483
    cpt props@{ boxes, nodeId } _ = do
484
      let sessionProps = RE.pick props :: Record SessionProps
485
      pure $ authed (Record.merge { content: \session ->
486
                                     dashboardLayout { boxes, nodeId, session } [] } sessionProps) []
487

arturo's avatar
arturo committed
488 489
--------------------------------------------------------------

arturo's avatar
arturo committed
490 491 492 493
type DocumentProps =
  ( listId :: ListId
  | SessionNodeProps
  )
494 495 496

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

498
documentCpt :: R.Component DocumentProps
James Laver's avatar
James Laver committed
499
documentCpt = here.component "document" cpt where
500
  cpt props@{ listId, nodeId } _ = do
arturo's avatar
arturo committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
    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 []
518

arturo's avatar
arturo committed
519 520
--------------------------------------------------------------

521 522
graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt
arturo's avatar
arturo committed
523

524 525
graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where
arturo's avatar
arturo committed
526
  cpt props@{ nodeId } _ = do
527
    let
arturo's avatar
arturo committed
528
      sessionProps = (RE.pick props :: Record SessionProps)
529 530 531 532

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
533
            \_ -> Graph.node
arturo's avatar
arturo committed
534 535 536
                  { graphId: nodeId
                  , key: "graphId-" <> show nodeId
                  }
arturo's avatar
arturo committed
537

538 539 540 541 542
        }
        sessionProps

    pure $ authed authedProps []

arturo's avatar
arturo committed
543
--------------------------------------------------------------
544

545 546
phyloExplorer :: R2.Component SessionNodeProps
phyloExplorer = R.createElement phyloExplorerCpt
arturo's avatar
arturo committed
547

548
phyloExplorerCpt :: R.Component SessionNodeProps
549
phyloExplorerCpt = here.component "phylo" cpt where
arturo's avatar
arturo committed
550
  cpt props@{ nodeId } _ = do
551 552 553 554 555 556
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
557
            \_ -> Phylo.node
arturo's avatar
arturo committed
558 559
                  { nodeId
                  }
560 561
        }
        sessionProps
562

563
    pure $ authed authedProps []
564

arturo's avatar
arturo committed
565
--------------------------------------------------------------
566

567 568 569
home :: R2.Component Props
home = R.createElement homeCpt
homeCpt :: R.Component Props
James Laver's avatar
James Laver committed
570
homeCpt = here.component "home" cpt where
571
  cpt { boxes } _ = do
572
    pure $ homeLayout { boxes }
573

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

576 577 578
lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
579
listsCpt = here.component "lists" cpt where
580
  cpt props@{ boxes
581
            , nodeId } _ = do
James Laver's avatar
James Laver committed
582
    let sessionProps = RE.pick props :: Record SessionProps
583
    pure $ authed (Record.merge { content: \session ->
584
                                   Lists.listsLayout { boxes
585
                                                     , nodeId
586
                                                     , session
587
                                                     , sessionUpdate: \_ -> pure unit } [] } sessionProps) []
James Laver's avatar
James Laver committed
588

arturo's avatar
arturo committed
589 590
--------------------------------------------------------------

591
login' :: Boxes -> R.Element
James Laver's avatar
James Laver committed
592
login' { backend, sessions, showLogin: visible } =
arturo's avatar
arturo committed
593 594 595 596 597 598
  login
  { backend
  , backends: A.fromFoldable defaultBackends
  , sessions
  , visible
  }
James Laver's avatar
James Laver committed
599

arturo's avatar
arturo committed
600 601
--------------------------------------------------------------

602 603 604
routeFile :: R2.Component SessionNodeProps
routeFile = R.createElement routeFileCpt
routeFileCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
605
routeFileCpt = here.component "routeFile" cpt where
606
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
607
    let sessionProps = RE.pick props :: Record SessionProps
608 609
    pure $ authed (Record.merge { content: \session ->
                                   fileLayout { nodeId, session } } sessionProps) []
610

arturo's avatar
arturo committed
611 612
--------------------------------------------------------------

arturo's avatar
arturo committed
613 614
type RouteFrameProps =
  ( nodeType :: NodeType
615 616 617 618 619
  | SessionNodeProps
  )

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

621
routeFrameCpt :: R.Component RouteFrameProps
James Laver's avatar
James Laver committed
622
routeFrameCpt = here.component "routeFrame" cpt where
623
  cpt props@{ nodeId, nodeType } _ = do
arturo's avatar
arturo committed
624 625 626 627 628 629 630
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \session ->
arturo's avatar
arturo committed
631
              Frame.node
arturo's avatar
arturo committed
632 633
              { nodeId
              , nodeType
arturo's avatar
arturo committed
634
              , key: show (sessionId session) <> "-" <> show nodeId
arturo's avatar
arturo committed
635 636 637 638 639 640
              }

        }
        sessionProps

    pure $ authed authedProps []
641

arturo's avatar
arturo committed
642 643
--------------------------------------------------------------

644 645 646
team :: R2.Component SessionNodeProps
team = R.createElement teamCpt
teamCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
647
teamCpt = here.component "team" cpt where
arturo's avatar
arturo committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
  cpt props@{ nodeId } _ = do
    let
      sessionProps = RE.pick props :: Record SessionProps

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

    pure $ authed authedProps []
663

arturo's avatar
arturo committed
664 665
--------------------------------------------------------------

666 667
texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt
arturo's avatar
arturo committed
668

669
textsCpt :: R.Component SessionNodeProps
arturo's avatar
arturo committed
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
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 []
686

arturo's avatar
arturo committed
687 688
--------------------------------------------------------------

689 690 691
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
692
userCpt = here.component "user" cpt where
693
  cpt props@{ boxes
694
            , nodeId } _ = do
James Laver's avatar
James Laver committed
695
    let sessionProps = RE.pick props :: Record SessionProps
696
    pure $ authed (Record.merge { content: \session ->
697
                                   userLayout { boxes
698
                                              , frontends: defaultFrontends
699
                                              , nodeId
700
                                              , session } [] } sessionProps) []
701

arturo's avatar
arturo committed
702 703
--------------------------------------------------------------

James Laver's avatar
James Laver committed
704
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
705 706 707 708

contact :: R2.Component ContactProps
contact = R.createElement contactCpt
contactCpt :: R.Component ContactProps
James Laver's avatar
James Laver committed
709
contactCpt = here.component "contact" cpt where
710
  cpt props@{ annuaireId
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
            , 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
726 727 728 729 730 731 732 733 734 735 736 737 738

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

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
739

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