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

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

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

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

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

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