Forest.purs 1.33 KB
Newer Older
1 2
module Gargantext.Components.Forest where

3
import Prelude (const, ($), (<$>))
4
import Data.Array as A
5 6 7 8 9 10
import Data.Maybe (Maybe(..))
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Ends (Frontends)
import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (Session(..), Sessions, unSessions)
11
import Gargantext.Components.Forest.Tree (treeView)
12 13 14
import Gargantext.Utils.Reactix as R2

type Props =
15 16
  ( sessions  :: Sessions
  , route     :: AppRoute
17
  , frontends :: Frontends
18 19
  , showLogin :: R2.Setter Boolean
  )
20 21 22 23 24 25 26

forest :: Record Props -> R.Element
forest props = R.createElement forestCpt props []

forestCpt :: R.Component Props
forestCpt = R.staticComponent "G.C.Forest.forest" cpt where
  cpt {sessions, route, frontends, showLogin} _ =
27
    R.fragment $ A.cons (plus showLogin) trees
28
    where
29 30 31
      trees = tree <$> unSessions sessions
      tree s@(Session {treeId}) =
        treeView { root: treeId, frontends, mCurrentRoute: Just route, session: s }
32

33
plus :: R2.Setter Boolean -> R.Element
34
plus showLogin =
Alexandre Delanoë's avatar
Alexandre Delanoë committed
35
  H.button {on: {click}, className: "btn btn-primary"}
36
  [ H.div { "type": ""
37
          , className: "fa fa-plus-circle fa-lg"
38
          } [H.text "Login"] ]
39 40
  -- TODO same as the one in the Login Modal (same CSS)
  -- [ H.i { className: "material-icons md-36"} [] ]
41 42 43
  where
    click _ = do
      showLogin (const true)