Forest.purs 4.43 KB
Newer Older
James Laver's avatar
James Laver committed
1
module Gargantext.Components.Forest
arturo's avatar
arturo committed
2
  ( forestLayout
3
  , Props
James Laver's avatar
James Laver committed
4
  ) where
5

6 7
import Gargantext.Prelude

8
import Data.Array as A
9
import Data.Maybe (Maybe(..))
arturo's avatar
arturo committed
10
import Gargantext.Components.App.Store (Boxes)
arturo's avatar
arturo committed
11 12
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Position(..), TooltipPosition(..), Variant(..))
13
import Gargantext.Components.Forest.Tree (treeLoader)
14
import Gargantext.Ends (Frontends)
arturo's avatar
arturo committed
15 16
import Gargantext.Hooks.LinkHandler (useLinkHandler)
import Gargantext.Routes (AppRoute(..))
17
import Gargantext.Sessions (Session(..), unSessions)
18
import Gargantext.Utils.Reactix as R2
19 20 21
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
James Laver's avatar
James Laver committed
22 23 24 25

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

26
-- Shared by components here with Tree
27
type Props =
28 29
  ( boxes     :: Boxes
  , frontends :: Frontends
30
  )
31

arturo's avatar
arturo committed
32 33 34 35 36
forestLayout :: R2.Leaf Props
forestLayout = R2.leaf forestLayoutCpt

forestLayoutCpt :: R.Component Props
forestLayoutCpt = here.component "forest" cpt where
37 38 39 40
  cpt { boxes: boxes@{ handed
                     , reloadForest
                     , sessions }
      , frontends } _ = do
41 42 43 44
    -- TODO Fix this. I think tasks shouldn't be a Box but only a Reductor
    -- tasks'        <- GAT.useTasks reloadRoot reloadForest
    -- R.useEffect' $ do
    --   T.write_ (Just tasks') tasks
James Laver's avatar
James Laver committed
45
    handed'       <- T.useLive T.unequal handed
46 47
    sessions'     <- T.useLive T.unequal sessions
    -- forestOpen'   <- T.useLive T.unequal forestOpen
48
    -- reloadRoot'   <- T.useLive T.unequal reloadRoot
49
    -- route'        <- T.useLive T.unequal route
50

James Laver's avatar
James Laver committed
51
    -- TODO If `reloadForest` is set, `reload` state should be updated
52
    -- TODO fix tasks ref
arturo's avatar
arturo committed
53 54 55 56
    pure $

      H.div
      { className: "forest-layout" }
57
      (A.cons (plus { boxes }) (trees handed' sessions'))
58 59
    where
      trees handed' sessions' = (tree handed') <$> unSessions sessions'
60
      tree handed' s@(Session { treeId }) =
arturo's avatar
arturo committed
61
        H.div
arturo's avatar
arturo committed
62
        { className: "forest-layout__tree" }
arturo's avatar
arturo committed
63
        [
64 65 66 67 68 69 70 71 72
          treeLoader
          { boxes
          , frontends
          , handed: handed'
          , reload: reloadForest
          , root: treeId
          , session: s
          , key: "tree-" <> (show treeId)
          }
arturo's avatar
arturo committed
73
        ]
74

75
type Plus = ( boxes :: Boxes )
76 77

plus :: R2.Leaf Plus
78
plus = R2.leafComponent plusCpt
79 80
plusCpt :: R.Component Plus
plusCpt = here.component "plus" cpt where
arturo's avatar
arturo committed
81 82 83
  cpt { boxes: { backend, showLogin } } _ = do
    -- Hooks
    { goToRoute } <- useLinkHandler
84

arturo's avatar
arturo committed
85 86 87 88 89 90 91 92 93 94 95
    -- Behaviors
    let
      click _ = do
        -- NOTE Reset backend in case G.C.N.Home.homeLayout set that to (Just b)
        -- from current url
        _ <- T.write Nothing backend
        T.write_ true showLogin

    -- Render
    pure $
      H.div
arturo's avatar
arturo committed
96
      { className: "forest-layout__action" }
97
      [
arturo's avatar
arturo committed
98 99 100 101 102 103 104
        B.tooltipContainer
        { delayShow: 600
        , position: TooltipPosition Top
        , tooltipSlot:
            B.span_ "Back to home"
        , defaultSlot:
            B.button
arturo's avatar
arturo committed
105
            { className: "forest-layout__action__button"
arturo's avatar
arturo committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
            , callback: const $ goToRoute Home
            , variant: ButtonVariant Light
            }
            [
              B.icon { name: "home" }
            ]
        }
      ,
        B.tooltipContainer
        { delayShow: 600
        , position: TooltipPosition Top
        , tooltipSlot:
            B.span_ "Add or remove connection to the server(s)"
        , defaultSlot:
            B.button
arturo's avatar
arturo committed
121
            { className: "forest-layout__action__button"
arturo's avatar
arturo committed
122 123 124 125
            , callback: click
            , variant: ButtonVariant Light
            }
            [
arturo's avatar
arturo committed
126 127
              B.icon
              { name: "universal-access" }
arturo's avatar
arturo committed
128
            ,
arturo's avatar
arturo committed
129
              B.wad_ [ "d-inline-block", "w-1" ]
arturo's avatar
arturo committed
130 131 132
            ,
              H.text $ "Log in/out"
            ]
133
        }
134
      ]
135 136
  --, H.div { "type": "", className: "fa fa-plus-circle fa-lg"} []
  --, H.div { "type": "", className: "fa fa-minus-circle fa-lg"} []
137 138
  -- TODO same as the one in the Login Modal (same CSS)
  -- [ H.i { className: "material-icons md-36"} [] ]
139

140

arturo's avatar
arturo committed
141 142 143 144 145
-- forestLayout :: R2.Leaf Props
-- forestLayout = R2.leaf forestLayoutCpt
-- forestLayoutCpt :: R.Memo Props
-- forestLayoutCpt = R.memo' $ here.component "forestLayout" cpt where
--   cpt p _ = pure $
146

arturo's avatar
arturo committed
147 148 149 150 151 152 153 154 155
--     H.div
--     { className: "forest-layout" }
--     [
--       H.div { className: "forest-layout__top-teaser" } []
--     ,
--       forest p []
--     ,
--       H.div { className: "forest-layout__bottom-teaser" } []
--     ]