TopBar.purs 9.65 KB
Newer Older
1
module Gargantext.Components.TopBar (component) where
2

3 4
import Gargantext.Prelude

5
import Data.Foldable (intercalate)
6 7
import Effect (Effect)
import Gargantext.Components.App.Store as AppStore
arturo's avatar
arturo committed
8 9
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Variant(..))
10
import Gargantext.Components.Lang (langSwitcher, allFeLangs)
arturo's avatar
arturo committed
11
import Gargantext.Components.Themes (themeSwitcher, allThemes)
12 13
import Gargantext.Types (Handed(..), defaultCacheParams)
import Gargantext.Utils (setter, (?))
14
import Gargantext.Utils.Reactix as R2
15 16 17
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
18

19 20
here :: R2.Here
here = R2.here "Gargantext.Components.TopBar"
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
component :: R2.Leaf ()
component = R2.leaf componentCpt
componentCpt :: R.Component ()
componentCpt = here.component "main" cpt where
  cpt _ _ = do
    -- | States
    -- |
    { lang
    , showTree
    , theme
    } <- AppStore.use

    showTree' <- R2.useLive' showTree

    -- | Effects
    -- |

    -- | Behaviors
    -- |
    let
      onTreeToggleClick _ = do
        let new = not showTree'
        T.write_ new showTree
        -- transfer local Component change to Local Storage
        onTreeToggleChange new

    -- | Render
    -- |
    pure $

      H.div
53
      { className: "main-topbar navbar navbar-expand-lg navbar-dark bg-dark py-0"
54 55 56 57 58 59 60 61 62 63 64 65 66 67
      , id: "dafixedtop"
      , role: "navigation"
      }
      [
        logo
      ,
        divDropdownLeft {} []
      ,
        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 main-topbar__hand-button"
        }
68
        [
69 70 71 72 73 74 75 76 77 78 79 80 81
          handedChooser
          {}
        ]
      ,
        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 main-topbar__help-button"
        }
        [
          H.a
          { className: "nav-link navbar-text" }
arturo's avatar
arturo committed
82
          [
83 84
            H.span
            { className: "fa fa-question-circle-o" } []
arturo's avatar
arturo committed
85
          ]
86
        ]
87 88 89 90 91 92 93 94 95
      ,
        H.li
        { className: "nav-item main-topbar__theme-switcher" }
        [
          themeSwitcher
          { theme
          , themes: allThemes
          } []
        ]
Alexandre Delanoë's avatar
Alexandre Delanoë committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

{-      ,
        H.li { className: "nav-item main-topbar__lang-switcher" }
          [ langSwitcher
            { lang
            , langs: allFeLangs
            } []
          ]-}
        , B.button
          { variant: showTree' ?
              ButtonVariant Light $
              OutlinedButtonVariant Light
          , callback: onTreeToggleClick
          , className: "main-topbar__tree-switcher"
          }
          [
            if showTree'
            then H.text "Hide Tree"
            else H.text "Show Tree"
          ]
        , H.div { id: "portal-topbar" } []
117 118 119 120 121 122 123 124 125 126 127
      ]

      -- SB.searchBar {session, databases: allDatabases}

onTreeToggleChange :: Boolean -> Effect Unit
onTreeToggleChange new = do
  cache <- R2.loadLocalStorageState' R2.appParamsKey defaultCacheParams
  let update = setter (_ { showTree = new }) cache
  R2.setLocalStorageState R2.appParamsKey update

----------------------------------------------------------
128

129 130 131
logo :: R.Element
logo =
  H.a { className, href: "#/" } [
132
    H.img { src, title, width: "46", height: "auto" }
133 134
  ]
  where
135
    className = "main-topbar__logo navbar-brand logoSmall"
136
    src       = "images/logoSmall.png"
137
    title     = "Back to home"
138 139


140 141 142
divDropdownLeft :: R2.Component ()
divDropdownLeft = R.createElement divDropdownLeftCpt
divDropdownLeftCpt :: R.Component ()
143
divDropdownLeftCpt = here.component "divDropdownLeft" cpt
144 145
  where
    cpt {} _ = do
146
      show <- T.useBox false
147

148
      pure $ H.li { className: "nav-item dropdown" } [
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
          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"
              }
165 166 167 168 169 170 171

      , LiNav { title : "Learn with us!"
              , href  : "https://iscpif.fr/projects/gargantext/"
              , icon  : "fa fa-life-ring"
              , text  : "Subscribe to Garg Lessons"
              }

172 173
      , LiNav { title : "Report bug here"
              , href  : "https://www.iscpif.fr/gargantext/feedback-and-bug-reports/"
174
              , icon  : "fa fa-bullhorn"
175 176 177 178 179
              , text  : "Feedback"
              }
      ]
      , -----------------------------------------------------------
      [ LiNav { title : "Chat"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
180
              , href  : "https://webchat.oftc.net/?channels=#gargantext"
181 182 183 184 185 186 187 188 189 190
              , icon  : "fa fa-rocket"
              , text  : "Chat"
              }
      , LiNav { title : "Forums"
              , href  : "https://discourse.iscpif.fr/c/gargantext"
              , icon  : "fa fa-weixin"
              , text  : "Forum"
              }
      ]
      ,------------------------------------------------------------
191 192 193

      [ LiNav { title : "Changelog"
              , href  : "https://gitlab.iscpif.fr/gargantext/main/blob/master/CHANGELOG.md"
194
              , icon  : "fa fa-clock-o"
195 196 197
              , text  : "Versions change"
              }
      , LiNav { title : "Code documentation"
198
              , href  : "https://doc.gargantext.org"
199
              , icon  : "fa fa-book"
200 201 202
              , text  : "Source Code Documentation"
              }
      , LiNav { title : "API documentation"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
203
              , href  : "https://cnrs.gargantext.org/swagger-ui"
204 205 206 207 208 209 210 211 212 213 214
              , 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"
              }
      ]

      ,------------------------------------------------------------
215 216
      [ LiNav { title : "Learn more about us"
              , href  : "https://iscpif.fr/projects/gargantext/"
217
              , icon  : "fa fa-question"
218 219 220 221 222 223 224
              , text  : "About"
              }
      ]
    ] -- ===========================================================

type MenuButtonProps = (
    element :: LiNav
225
  , show    :: T.Box Boolean
226 227 228 229
  )

menuButton :: R2.Component MenuButtonProps
menuButton = R.createElement menuButtonCpt
230
menuButtonCpt :: R.Component MenuButtonProps
231
menuButtonCpt = here.component "menuButton" cpt
232
  where
233
    cpt { element: LiNav { icon, text, title }, show } _ = do
234 235
      pure $ H.a { className: "dropdown-toggle navbar-text"
                -- , data: {toggle: "dropdown"}
236
                , title
237
                , on: { click: \_ -> T.modify_ not show }
238 239 240 241 242 243 244 245
                , role: "button" } [
          H.span { aria: {hidden : true}, className: icon } []
        , H.text (" " <> text)
        ]

-- | Menu in the sidebar, syntactic sugar
type MenuElementsProps = (
    elements :: Array (Array LiNav)
246
  , show     :: T.Box Boolean
247
  )
248

249 250
menuElements :: R2.Component MenuElementsProps
menuElements = R.createElement menuElementsCpt
251
menuElementsCpt :: R.Component MenuElementsProps
252
menuElementsCpt = here.component "menuElements" cpt
253
  where
254 255 256 257 258 259 260 261 262 263 264
    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"} []]
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

-- | 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'
             }
286 287 288 289 290 291 292
      ) = H.li { className: "dropdown-item" } [
            H.a { tabIndex: (-1)
                , target: "blank"
                , title: title'
                , href: href'
                } [ H.span { className: icon' } []
                  , H.text $ " " <> text'
293
                  ]
294
            ]
295

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
------------------------------------------------------

handedChooser :: R2.Leaf ()
handedChooser = R2.leaf handedChooserCpt
handedChooserCpt :: R.Component ()
handedChooserCpt = here.component "handedChooser" cpt where
  cpt _ _ = do
    -- | States
    -- |
    { handed
    } <- AppStore.use

    handed' <- R2.useLive' handed

    -- | Computed
    -- |
    let
      handedClass LeftHanded = "fa fa-hand-o-left"
      handedClass RightHanded = "fa fa-hand-o-right"

    -- | Behaviors
    -- |
    let
      onClick :: Unit -> Effect Unit
      onClick _ = flip T.modify_ handed case _ of
        LeftHanded  -> RightHanded
        RightHanded -> LeftHanded

    -- | Render
    -- |
    pure $

      H.a
      { className: "nav-link navbar-text" }
      [
        H.span
        { className: handedClass handed'
        , on: { click: onClick }
        } []
      ]