Router.purs 24.4 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.Bootstrap as B
16
import Gargantext.Components.ErrorsView as ErrorsView
arturo's avatar
arturo committed
17
import Gargantext.Components.Forest (forestLayout)
18
import Gargantext.Components.Forest.Breadcrumb as Breadcrumb
Karen Konou's avatar
Karen Konou committed
19
import Gargantext.Components.ForgotPassword (forgotPasswordLayout)
20
-- import Gargantext.Components.GraphQL.Node (Node)
21
import Gargantext.Components.Login (login)
James Laver's avatar
James Laver committed
22
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
23
import Gargantext.Components.Nodes.Annuaire.User (userLayout)
James Laver's avatar
James Laver committed
24
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
arturo's avatar
arturo committed
25
import Gargantext.Components.Nodes.Corpus as Corpus
26
import Gargantext.Components.Nodes.Corpus.Code (corpusCodeLayout)
James Laver's avatar
James Laver committed
27
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
arturo's avatar
arturo committed
28 29
import Gargantext.Components.Nodes.Corpus.Document as Document
import Gargantext.Components.Nodes.Corpus.Phylo as Phylo
James Laver's avatar
James Laver committed
30
import Gargantext.Components.Nodes.File (fileLayout)
arturo's avatar
arturo committed
31
import Gargantext.Components.Nodes.Frame as Frame
Karen Konou's avatar
Karen Konou committed
32
import Gargantext.Components.Nodes.Graph as Graph
James Laver's avatar
James Laver committed
33 34 35
import Gargantext.Components.Nodes.Home (homeLayout)
import Gargantext.Components.Nodes.Lists as Lists
import Gargantext.Components.Nodes.Texts as Texts
36
import Gargantext.Components.Tile (tileBlock)
37
import Gargantext.Components.TopBar as TopBar
Karen Konou's avatar
Karen Konou committed
38
import Gargantext.Components.TreeSearch (treeSearch)
James Laver's avatar
James Laver committed
39
import Gargantext.Config (defaultFrontends, defaultBackends)
40
import Gargantext.Config.REST (AffRESTError, logRESTError)
arturo's avatar
arturo committed
41
import Gargantext.Context.Session as SessionContext
James Laver's avatar
James Laver committed
42
import Gargantext.Ends (Backend)
arturo's avatar
arturo committed
43
import Gargantext.Hooks.Resize (ResizeType(..), useResizeHandler)
arturo's avatar
arturo committed
44
import Gargantext.Hooks.Session (useSession)
45
import Gargantext.Routes (AppRoute, Tile)
46
import Gargantext.Routes as GR
arturo's avatar
arturo committed
47
import Gargantext.Sessions (Session, sessionId)
48
import Gargantext.Sessions as Sessions
49
import Gargantext.Types (CorpusId, Handed(..), ListId, NodeID, NodeType(..), SessionId, SidePanelState(..))
arturo's avatar
arturo committed
50
import Gargantext.Utils ((?))
51
import Gargantext.Utils.Reactix (getElementById)
James Laver's avatar
James Laver committed
52
import Gargantext.Utils.Reactix as R2
53 54
import Reactix as R
import Reactix.DOM.HTML as H
55
import Record (get)
56 57 58
import Record as Record
import Record.Extra as RE
import Toestand as T
59
import Type.Proxy (Proxy(..))
James Laver's avatar
James Laver committed
60 61 62 63

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

64
type Props = ( boxes :: Boxes )
James Laver's avatar
James Laver committed
65

66
type SessionProps = ( sessionId :: SessionId | Props )
67

68
type SessionNodeProps = ( nodeId :: NodeID | SessionProps )
69
type Props' = ( backend :: Backend, route' :: AppRoute | Props )
70

71 72
type NodeProps = ( nodeId :: NodeID | Props )

James Laver's avatar
James Laver committed
73
router :: R2.Leaf Props
74
router = R2.leaf routerCpt
James Laver's avatar
James Laver committed
75
routerCpt :: R.Component Props
76
routerCpt = here.component "router" cpt where
77
  cpt { boxes: boxes@{ handed } } _ = do
78
    -- States
arturo's avatar
arturo committed
79
    handed'     <- R2.useLive' handed
80

81
    -- Computed
82
    let
83
      handedClassName :: Handed -> String
84 85 86 87
      handedClassName = case _ of
        LeftHanded  -> "left-handed"
        RightHanded -> "right-handed"

88 89 90 91 92 93 94 95 96 97 98 99 100 101
      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')
102

103
    -- Render
arturo's avatar
arturo committed
104 105 106 107 108
    pure $

      H.div
      { className: "router" }
      [
109
        login' boxes
Karen Konou's avatar
Karen Konou committed
110 111
      ,
        treeSearch' boxes
112 113 114 115 116 117 118 119 120 121
      ,
        TopBar.component
        {}
      ,
        ErrorsView.component
        {}
      ,
        H.div
        { className: "router__inner" }
        [
arturo's avatar
arturo committed
122
          forest { boxes }
123
        ,
arturo's avatar
arturo committed
124
          mainPage { boxes }
125
        ,
arturo's avatar
arturo committed
126
          sidePanel { boxes }
127 128
        ]
      ]
129

arturo's avatar
arturo committed
130
--------------------------------------------------------------
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
-- breadcrumb :: R2.Leaf NodeProps
-- breadcrumb = R2.leaf breadcrumbCpt
-- breadcrumbCpt :: R.Component NodeProps
-- breadcrumbCpt = here.component "breadcrumb" cpt where
--   cpt props@{ nodeId } _ = do
--     let
--       sessionProps = RE.pick props :: Record SessionProps
--       authedProps =
--         -- Record.merge { content: \session -> breadcrumbLayout 
--         --                                       { boxes
--         --                                       , frontends: defaultFrontends
--         --                                       , nodeId
--         --                                       , session } } sessionProps
--         Record.merge { content: \_ -> breadcrumbLayout { nodeId } } sessionProps
    
--     pure $ authed authedProps []
--     -- pure $ breadcrumbLayout { nodeId }
--------------------------------------------------------------

151
mainPage :: R2.Leaf Props
152
mainPage = R2.leaf mainPageCpt
153 154 155
mainPageCpt :: R.Component Props
mainPageCpt = here.component "mainPage" cpt where
  cpt { boxes } _ = do
156 157 158 159 160 161 162 163 164
    -- 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
165 166 167 168
      deleteTile ::
           Record Tile
        -> T.Box (Array (Record Tile))
        -> (Unit -> Effect Unit)
169 170
      deleteTile tile listBox = const do
        list <- T.read listBox
171
        newList <- pure $ filter (not $ findTile $ tile.id) list
172 173 174 175
        T.write_ newList listBox

    let hasHorizontalTiles = not $ eq 0 $ length tileAxisXList
    let hasVerticalTiles = not $ eq 0 $ length tileAxisYList
176

177 178 179
    -- Render
    pure $

arturo's avatar
arturo committed
180
      H.div { className: "router__body main-page" }
181
      [
182 183 184
        Breadcrumb.component
        { boxes }
      ,
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        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
246
--------------------------------------------------------------
247

248
forest :: R2.Leaf Props
arturo's avatar
arturo committed
249 250 251
forest = R2.leaf forestCpt
forestCpt :: R.Memo Props
forestCpt = R.memo' $ here.component "forest" cpt where
arturo's avatar
arturo committed
252
  cpt { boxes } _ = do
arturo's avatar
arturo committed
253 254 255
    -- States
    showTree' <- R2.useLive' boxes.showTree

arturo's avatar
arturo committed
256 257 258 259
    -- Hooks
    resizeHandler <- useResizeHandler

    -- Effects
arturo's avatar
arturo committed
260
    R.useLayoutEffect1' [] do
arturo's avatar
arturo committed
261 262 263 264 265 266
      resizeHandler.add
        ".router__aside__handle__action"
        ".router__aside"
        Vertical
      pure $ resizeHandler.remove
        ".router__aside__handle__action"
arturo's avatar
arturo committed
267 268

    -- Render
269 270
    pure $

arturo's avatar
arturo committed
271
      H.div
arturo's avatar
arturo committed
272 273 274 275
      { 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
276
      }
arturo's avatar
arturo committed
277
      [
arturo's avatar
arturo committed
278 279 280 281 282 283 284 285
        H.div
        { className: "router__aside__inner" }
        [
          forestLayout
          { boxes
          , frontends: defaultFrontends
          }
        ]
arturo's avatar
arturo committed
286 287
      ,
        H.div
arturo's avatar
arturo committed
288
        { className: "router__aside__handle"
arturo's avatar
arturo committed
289 290 291
        }
        [
          H.div
arturo's avatar
arturo committed
292
          { className: "router__aside__handle__action" }
arturo's avatar
arturo committed
293 294 295
          []
        ]
      ]
296

arturo's avatar
arturo committed
297 298
--------------------------------------------------------------

299
sidePanel :: R2.Leaf Props
300
sidePanel = R2.leaf sidePanelCpt
301
sidePanelCpt :: R.Component Props
302
sidePanelCpt = here.component "sidePanel" cpt where
303 304
  cpt props@{ boxes: { session
                     , sidePanelState } } _ = do
305
    session' <- T.useLive T.unequal session
306
    sidePanelState' <- T.useLive T.unequal sidePanelState
307

308 309
    case session' of
      Nothing -> pure $ H.div {} []
arturo's avatar
arturo committed
310
      Just _  ->
311
        case sidePanelState' of
arturo's avatar
arturo committed
312 313 314
          Opened -> pure $
            R.provideContext SessionContext.context session'
            [ openedSidePanel props ]
315
          _      -> pure $ H.div {} []
316

arturo's avatar
arturo committed
317 318
--------------------------------------------------------------

319 320 321 322 323 324
type RenderRouteProps =
  ( route :: AppRoute
  | Props
  )

renderRoute :: R2.Leaf RenderRouteProps
arturo's avatar
arturo committed
325 326 327 328
renderRoute = R2.leaf renderRouteCpt

renderRouteCpt :: R.Memo RenderRouteProps
renderRouteCpt = R.memo' $ here.component "renderRoute" cpt where
329 330 331 332 333 334
  cpt { boxes, route } _ = do
    let sessionNodeProps sId nId =
          { nodeId: nId
          , sessionId: sId
          , boxes
          }
335 336

    pure $ R.fragment
337
      [ case route of
338 339 340
        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) []
341
        GR.CorpusCode s n         -> corpusCode (sessionNodeProps s n) []
342 343 344 345 346 347 348 349 350 351
        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
352
        GR.TreeFlat _ _ _         -> treeSearch' boxes
353
        GR.PGraphExplorer s g     -> graphExplorer (sessionNodeProps s g) []
354
        GR.PhyloExplorer s g      -> phyloExplorer (sessionNodeProps s g) []
355
        GR.RouteFile s n          -> routeFile (sessionNodeProps s n) []
356
        GR.RouteFrameWrite s n    -> routeFrame (Record.merge { nodeType: Notes    } $ sessionNodeProps s n) []
357
        GR.RouteFrameCalc  s n    -> routeFrame (Record.merge { nodeType: Calc     } $ sessionNodeProps s n) []
358
        GR.RouteFrameCode  s n    -> routeFrame (Record.merge { nodeType: NodeFrameNotebook } $ sessionNodeProps s n) []
359
        GR.RouteFrameVisio s n    -> routeFrame (Record.merge { nodeType: NodeFrameVisio    } $ sessionNodeProps s n) []
360
        GR.Team s n               -> team (sessionNodeProps s n) []
361
        GR.NodeTexts s n          -> texts (sessionNodeProps s n) []
362
        GR.UserPage s n           -> user (sessionNodeProps s n) []
Karen Konou's avatar
Karen Konou committed
363
        GR.ForgotPassword p       -> forgotPassword {boxes, params: p} []
364 365
      ]

arturo's avatar
arturo committed
366 367
--------------------------------------------------------------

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
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
386 387
      Nothing -> pure $
        home homeProps []
arturo's avatar
arturo committed
388
      Just s -> pure $
arturo's avatar
arturo committed
389
        R.provideContext SessionContext.context session' [ content s ]
390 391 392
    where
      homeProps = RE.pick props :: Record Props

arturo's avatar
arturo committed
393 394
--------------------------------------------------------------

arturo's avatar
arturo committed
395 396 397
openedSidePanel :: R2.Leaf Props
openedSidePanel = R2.leaf openedSidePanelCpt
openedSidePanelCpt :: R.Component Props
398
openedSidePanelCpt = here.component "openedSidePanel" cpt where
arturo's avatar
arturo committed
399 400
  cpt { boxes:
        { route
401
        , sidePanelLists
arturo's avatar
arturo committed
402 403 404 405
        , sidePanelState
        }
      } _ = do
    session <- useSession
arturo's avatar
arturo committed
406

407
    route' <- T.useLive T.unequal route
408

409
    let wrapper = H.div { className: "side-panel shadow" }
410

411 412
    selectedNgrams <- T.useBox Nothing

413
    case route' of
414
      GR.Lists _s _n -> do
415
        pure $ wrapper
416
          [ Lists.sidePanel { session
417
                            , sidePanel: sidePanelLists
418
                            , sidePanelState } [] ]
arturo's avatar
arturo committed
419 420
      GR.NodeTexts _s _n ->
        pure $ wrapper [ Texts.textsSidePanel {} ]
421
      _ -> pure $ wrapper []
422

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

425 426 427
annuaire :: R2.Component SessionNodeProps
annuaire = R.createElement annuaireCpt
annuaireCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
428
annuaireCpt = here.component "annuaire" cpt where
429
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
430
    let sessionProps = RE.pick props :: Record SessionProps
431 432 433 434
    pure $ authed (Record.merge { content: \session ->
                                   annuaireLayout { frontends: defaultFrontends
                                                  , nodeId
                                                  , session } } sessionProps) []
435

arturo's avatar
arturo committed
436 437
--------------------------------------------------------------

438 439 440
corpus :: R2.Component SessionNodeProps
corpus = R.createElement corpusCpt
corpusCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
441
corpusCpt = here.component "corpus" cpt where
arturo's avatar
arturo committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
  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 []
457

arturo's avatar
arturo committed
458 459
--------------------------------------------------------------

460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
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
479 480
--------------------------------------------------------------

James Laver's avatar
James Laver committed
481 482
type CorpusDocumentProps =
  ( corpusId :: CorpusId
483
  , listId :: ListId
484 485 486 487 488
  | SessionNodeProps
  )

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

490
corpusDocumentCpt :: R.Component CorpusDocumentProps
arturo's avatar
arturo committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
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 []
510

arturo's avatar
arturo committed
511 512
--------------------------------------------------------------

513 514 515 516 517
dashboard :: R2.Component SessionNodeProps
dashboard = R.createElement dashboardCpt
dashboardCpt :: R.Component SessionNodeProps
dashboardCpt = here.component "dashboard" cpt
  where
518
    cpt props@{ boxes, nodeId } _ = do
519
      let sessionProps = RE.pick props :: Record SessionProps
520
      pure $ authed (Record.merge { content: \session ->
521
                                     dashboardLayout { boxes, nodeId, session } [] } sessionProps) []
522

arturo's avatar
arturo committed
523 524
--------------------------------------------------------------

arturo's avatar
arturo committed
525 526 527 528
type DocumentProps =
  ( listId :: ListId
  | SessionNodeProps
  )
529 530 531

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

533
documentCpt :: R.Component DocumentProps
James Laver's avatar
James Laver committed
534
documentCpt = here.component "document" cpt where
535
  cpt props@{ listId, nodeId } _ = do
arturo's avatar
arturo committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    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 []
553

arturo's avatar
arturo committed
554 555
--------------------------------------------------------------

556 557
graphExplorer :: R2.Component SessionNodeProps
graphExplorer = R.createElement graphExplorerCpt
arturo's avatar
arturo committed
558

559 560
graphExplorerCpt :: R.Component SessionNodeProps
graphExplorerCpt = here.component "graphExplorer" cpt where
arturo's avatar
arturo committed
561
  cpt props@{ nodeId } _ = do
562
    let
arturo's avatar
arturo committed
563
      sessionProps = (RE.pick props :: Record SessionProps)
564 565 566 567

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
568
            \_ -> Graph.node
arturo's avatar
arturo committed
569 570 571
                  { graphId: nodeId
                  , key: "graphId-" <> show nodeId
                  }
arturo's avatar
arturo committed
572

573 574 575 576 577
        }
        sessionProps

    pure $ authed authedProps []

arturo's avatar
arturo committed
578
--------------------------------------------------------------
579

580 581 582
phyloExplorer :: R2.Component SessionNodeProps
phyloExplorer = R.createElement phyloExplorerCpt
phyloExplorerCpt :: R.Component SessionNodeProps
583
phyloExplorerCpt = here.component "phylo" cpt where
arturo's avatar
arturo committed
584
  cpt props@{ nodeId } _ = do
585 586 587 588 589 590
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
arturo's avatar
arturo committed
591
            \_ -> Phylo.node
arturo's avatar
arturo committed
592 593
                  { nodeId
                  }
594 595
        }
        sessionProps
596

597
    pure $ authed authedProps []
598

arturo's avatar
arturo committed
599
--------------------------------------------------------------
600

601 602 603
home :: R2.Component Props
home = R.createElement homeCpt
homeCpt :: R.Component Props
James Laver's avatar
James Laver committed
604
homeCpt = here.component "home" cpt where
605
  cpt { boxes } _ = do
606
    pure $ homeLayout { boxes }
607

arturo's avatar
arturo committed
608 609
--------------------------------------------------------------

610 611 612
lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
613
listsCpt = here.component "lists" cpt where
614
  cpt props@{ boxes
615
            , nodeId } _ = do
James Laver's avatar
James Laver committed
616
    let sessionProps = RE.pick props :: Record SessionProps
617
    pure $ authed (Record.merge { content: \session ->
618
                                   Lists.listsLayout { boxes
619
                                                     , nodeId
620
                                                     , session
621 622
                                                     , sessionUpdate: \_ -> pure unit
                                                     , sidePanel: boxes.sidePanelLists } [] } sessionProps) []
James Laver's avatar
James Laver committed
623

arturo's avatar
arturo committed
624 625
--------------------------------------------------------------

626
login' :: Boxes -> R.Element
James Laver's avatar
James Laver committed
627
login' { backend, sessions, showLogin: visible } =
arturo's avatar
arturo committed
628 629 630 631 632 633
  login
  { backend
  , backends: A.fromFoldable defaultBackends
  , sessions
  , visible
  }
James Laver's avatar
James Laver committed
634

arturo's avatar
arturo committed
635 636
--------------------------------------------------------------

Karen Konou's avatar
Karen Konou committed
637 638 639 640 641 642
treeSearch' :: Boxes -> R.Element
treeSearch' { sessions, showSearch: visible } =
  treeSearch { sessions, visible }

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

643 644 645
routeFile :: R2.Component SessionNodeProps
routeFile = R.createElement routeFileCpt
routeFileCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
646
routeFileCpt = here.component "routeFile" cpt where
647
  cpt props@{ nodeId } _ = do
James Laver's avatar
James Laver committed
648
    let sessionProps = RE.pick props :: Record SessionProps
649 650
    pure $ authed (Record.merge { content: \session ->
                                   fileLayout { nodeId, session } } sessionProps) []
651

arturo's avatar
arturo committed
652 653
--------------------------------------------------------------

arturo's avatar
arturo committed
654 655
type RouteFrameProps =
  ( nodeType :: NodeType
656 657 658 659 660
  | SessionNodeProps
  )

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

662
routeFrameCpt :: R.Component RouteFrameProps
James Laver's avatar
James Laver committed
663
routeFrameCpt = here.component "routeFrame" cpt where
664
  cpt props@{ nodeId, nodeType } _ = do
arturo's avatar
arturo committed
665 666 667 668 669 670 671
    let
      sessionProps = (RE.pick props :: Record SessionProps)

      authedProps =
        Record.merge
        { content:
            \session ->
arturo's avatar
arturo committed
672
              Frame.node
arturo's avatar
arturo committed
673 674
              { nodeId
              , nodeType
arturo's avatar
arturo committed
675
              , key: show (sessionId session) <> "-" <> show nodeId
arturo's avatar
arturo committed
676 677 678 679 680 681
              }

        }
        sessionProps

    pure $ authed authedProps []
682

arturo's avatar
arturo committed
683 684
--------------------------------------------------------------

685 686 687
team :: R2.Component SessionNodeProps
team = R.createElement teamCpt
teamCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
688
teamCpt = here.component "team" cpt where
arturo's avatar
arturo committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
  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 []
704

arturo's avatar
arturo committed
705 706
--------------------------------------------------------------

707 708 709
texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt
textsCpt :: R.Component SessionNodeProps
arturo's avatar
arturo committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
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 []
726

arturo's avatar
arturo committed
727 728
--------------------------------------------------------------

729 730 731
user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
James Laver's avatar
James Laver committed
732
userCpt = here.component "user" cpt where
733
  cpt props@{ boxes
734
            , nodeId } _ = do
James Laver's avatar
James Laver committed
735
    let sessionProps = RE.pick props :: Record SessionProps
736
    pure $ authed (Record.merge { content: \session ->
737
                                   userLayout { boxes
738
                                              , frontends: defaultFrontends
739
                                              , nodeId
740
                                              , session } [] } sessionProps) []
741

arturo's avatar
arturo committed
742 743
--------------------------------------------------------------

James Laver's avatar
James Laver committed
744
type ContactProps = ( annuaireId :: NodeID | SessionNodeProps )
745 746 747 748

contact :: R2.Component ContactProps
contact = R.createElement contactCpt
contactCpt :: R.Component ContactProps
James Laver's avatar
James Laver committed
749
contactCpt = here.component "contact" cpt where
750
  cpt props@{ annuaireId
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
            , 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
766 767 768 769 770 771 772 773 774 775 776 777 778

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

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
779

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