TopBar.purs 8.75 KB
Newer Older
1 2 3 4
module Gargantext.Components.TopBar where

import Data.Foldable (intercalate)
import Data.Tuple.Nested ((/\))
5 6
import Reactix as R
import Reactix.DOM.HTML as H
7
import Toestand as T
8

9
import Gargantext.Prelude
10 11

import Gargantext.Components.Themes (themeSwitcher, defaultTheme, allThemes)
12
import Gargantext.Types (Handed(..), reverseHanded)
13
import Gargantext.Utils.Reactix as R2
14

15 16
here :: R2.Here
here = R2.here "Gargantext.Components.TopBar"
17

18
type TopBarProps = ( handed :: T.Box Handed )
19

20 21
topBar :: R2.Component TopBarProps
topBar = R.createElement topBarCpt
22 23

topBarCpt :: R.Component TopBarProps
24
topBarCpt = here.component "topBar" cpt
25
  where
26
    cpt { handed } _children = do
27 28 29 30
      handed' <- T.useLive T.unequal handed

      pure $ H.div { className: "navbar navbar-expand-lg navbar-dark bg-dark fixed-top"
                   , id: "dafixedtop"
31
                   , role: "navigation"
32
                   } $ reverseHanded handed' [
33 34 35 36
                      -- NOTE: first (and only) entry in the sorted array should have the "ml-auto class"
                      -- https://stackoverflow.com/questions/19733447/bootstrap-navbar-with-left-center-or-right-aligned-items
                      -- In practice: only apply "ml-auto" to the last element of this list, if handed == LeftHanded
                      logo
37
                   , H.ul { className: "navbar-nav " <> if handed' == LeftHanded then "ml-auto" else "" } $ reverseHanded handed' [
38 39 40 41 42
                        divDropdownLeft {} []
                      , handButton handed'
                      , smiley
                      , H.li { className: "nav-item" } [ themeSwitcher { theme: defaultTheme
                                                                       , themes: allThemes } [] ]
43 44
                      ]
                   ]
45
          where
46 47 48 49 50
            handButton handed' = H.li { title: "If you are Left Handed you can change\n"
                                            <> "the interface by clicking on me. Click\n"
                                            <> "again to come back to previous state."
                                      , className: "nav-item"
                                      } [handedChooser { handed } []]
51

52 53 54 55 56 57
            smiley = H.li { title: "Hello! Looking for the tree ?\n"
                                <> "Just watch on the other side!\n"
                                <> "Click on the hand again to see it back."
                          , className : "nav-item"
                          }
                          [ H.a { className: "nav-link" } [H.span {className: "fa fa-question-circle-o"} [] ]]
58 59 60 61 62 63 64 65

                        {-, H.ul { title: "Dark Mode soon here"
                                , className : "nav navbar-nav"
                                } [ H.li {} [ H.a {} [ H.span {className : "fa fa-moon"}[]
                                                          ]
                                                ]
                                      ]
                              -}
66

67 68 69
            -- SB.searchBar {session, databases: allDatabases}


70 71 72 73
logo :: R.Element
logo =
  H.a { className, href: "#/" } [
    H.img { src, title, width: "30", height: "28" }
74 75
  ]
  where
76
    className = "navbar-brand logoSmall"
77
    src       = "images/logoSmall.png"
78
    title     = "Back home."
79 80


81 82
divDropdownLeft :: R2.Component ()
divDropdownLeft = R.createElement divDropdownLeftCpt
83

84
divDropdownLeftCpt :: R.Component ()
85
divDropdownLeftCpt = here.component "divDropdownLeft" cpt
86 87
  where
    cpt {} _ = do
88
      show <- T.useBox false
89

90
      pure $ H.li { className: "nav-item dropdown" } [
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
          menuButton { element: menuElement, show } []
        , menuElements { elements, show } []
        ]

    menuElement = LiNav { title : "About Gargantext"
                        , href  : "#"
                        , icon  : "fa fa-info-circle"
                        , text  : "Info" }

    elements = [
      [
        LiNav { title : "Quick start, tutorials and methodology"
              , href  : "https://iscpif.fr/gargantext/your-first-map/"
              , icon  : "fa fa-lightbulb-o"
              , text  : "Tutorials"
              }
      , LiNav { title : "Report bug here"
              , href  : "https://www.iscpif.fr/gargantext/feedback-and-bug-reports/"
109
              , icon  : "fa fa-bullhorn"
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
              , text  : "Feedback"
              }
      ]
      , -----------------------------------------------------------
      [ LiNav { title : "Chat"
              , href  : "https://chat.iscpif.fr/channel/gargantext"
              , icon  : "fa fa-rocket"
              , text  : "Chat"
              }
      , LiNav { title : "Forums"
              , href  : "https://discourse.iscpif.fr/c/gargantext"
              , icon  : "fa fa-weixin"
              , text  : "Forum"
              }
      ]
      ,------------------------------------------------------------
      [ LiNav { title : "Code documentation"
              , href  : "https://doc.gargantext.org"
128
              , icon  : "fa fa-book"
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
              , text  : "Source Code Documentation"
              }
      , LiNav { title : "API documentation"
              , href  : "https://v4.gargantext.org/swagger-ui"
              , icon  : "fa fa-code-fork"
              , text  : "API documentation"
              }
      , LiNav { title : "Source code"
              , href  : "https://gitlab.iscpif.fr/gargantext/haskell-gargantext"
              , icon  : "fa fa-code"
              , text  : "Source Code"
              }
      ]

      ,------------------------------------------------------------
      [ LiNav { title : "More about us (you)"
              , href  : "https://iscpif.fr"
146
              , icon  : "fa fa-question"
147 148 149 150 151 152 153
              , text  : "About"
              }
      ]
    ] -- ===========================================================

type MenuButtonProps = (
    element :: LiNav
154
  , show    :: T.Box Boolean
155 156 157 158 159
  )

menuButton :: R2.Component MenuButtonProps
menuButton = R.createElement menuButtonCpt

160
menuButtonCpt :: R.Component MenuButtonProps
161
menuButtonCpt = here.component "menuButton" cpt
162
  where
163
    cpt { element: LiNav { title, href, icon, text }, show } _ = do
164 165 166
      pure $ H.a { className: "dropdown-toggle navbar-text"
                -- , data: {toggle: "dropdown"}
                , href, title
167
                , on: { click: \_ -> T.modify_ not show }
168 169 170 171 172 173 174 175
                , role: "button" } [
          H.span { aria: {hidden : true}, className: icon } []
        , H.text (" " <> text)
        ]

-- | Menu in the sidebar, syntactic sugar
type MenuElementsProps = (
    elements :: Array (Array LiNav)
176
  , show     :: T.Box Boolean
177
  )
178

179 180 181
menuElements :: R2.Component MenuElementsProps
menuElements = R.createElement menuElementsCpt

182
menuElementsCpt :: R.Component MenuElementsProps
183
menuElementsCpt = here.component "menuElements" cpt
184
  where
185 186 187 188 189 190 191 192 193 194 195
    cpt { elements, show } _ = do
      show' <- T.useLive T.unequal show

      pure $ if show' then
               H.ul { className: "dropdown-menu"
                    , on: { click: \_ -> T.write_ false show }
                    , style: { display: "block" } } $ intercalate divider $ map (map liNav) elements
             else
               H.div {} []
    divider :: Array R.Element
    divider = [H.li {className: "dropdown-divider"} []]
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216

-- | surgar for target : "blank"
--data LiNav_ = LiNav_ { title  :: String
--                     , href   :: String
--                     , icon   :: String
--                     , text   :: String
--                     , target :: String
--                     }

data LiNav = LiNav { title :: String
                   , href  :: String
                   , icon  :: String
                   , text  :: String
                   }

liNav :: LiNav -> R.Element
liNav (LiNav { title : title'
             , href  : href'
             , icon  : icon'
             , text  : text'
             }
217 218 219 220 221 222 223
      ) = H.li { className: "dropdown-item" } [
            H.a { tabIndex: (-1)
                , target: "blank"
                , title: title'
                , href: href'
                } [ H.span { className: icon' } []
                  , H.text $ " " <> text'
224
                  ]
225
            ]
226 227 228


type HandedChooserProps = (
229
  handed :: T.Box Handed
230 231
  )

232 233
handedChooser :: R2.Component HandedChooserProps
handedChooser = R.createElement handedChooserCpt
234 235

handedChooserCpt :: R.Component HandedChooserProps
236
handedChooserCpt = here.component "handedChooser" cpt
237 238
  where
    cpt { handed } _ = do
239 240
      handed' <- T.useLive T.unequal handed

241
      pure $ H.a { className: "nav-link" } [
242
        H.span { className: handedClass handed'
243
               , on: { click: onClick handed } } []
244 245
        ]

246 247
    handedClass LeftHanded = "fa fa-hand-o-left"
    handedClass RightHanded = "fa fa-hand-o-right"
248

249
    onClick handed = T.modify_ (\h -> case h of
250
      LeftHanded  -> RightHanded
251
      RightHanded -> LeftHanded) handed