TopBar.purs 8.6 KB
Newer Older
1 2 3 4 5 6 7 8
module Gargantext.Components.TopBar where

import Data.Array (reverse)
import Data.Foldable (intercalate)
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import Gargantext.Prelude
import Gargantext.Types (Handed(..))
9
import Gargantext.Utils.Reactix as R2
10 11
import Reactix as R
import Reactix.DOM.HTML as H
12 13 14 15

thisModule :: String
thisModule = "Gargantext.Components.TopBar"

16
type TopBarProps = (handed :: R.State Handed)
17

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

topBarCpt :: R.Component TopBarProps
topBarCpt = R.hooksComponentWithModule thisModule "topBar" cpt
  where
24
    cpt { handed } _children = do
25 26
      pure $ H.div { id: "dafixedtop"
                   , role: "navigation"
27
                   , className: "navbar navbar-expand-lg navbar-dark bg-dark fixed-top"
28 29 30 31 32
                   } $ sortHanded [
                     -- 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
33
                   , H.ul { className: "navbar-nav " <> if fst handed == LeftHanded then "ml-auto" else "" } $ sortHanded [
34
                       divDropdownLeft {} []
35 36
                     , handButton handed
                     , smiley
37
                     ]
38
                   ]
39
          where
40
            handButton handed = H.li { title: "If you are Left Handed you can change\n"
41
                                           <> "the interface by clicking on me. Click\n"
42
                                           <> "again to come back to previous state."
43
                                     , className: "nav-item"
44 45
                                     } [handedChooser { handed } []]

46 47 48 49 50 51
            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"} [] ]]
52 53 54 55 56 57 58 59

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

61
            sortHanded = if fst handed == LeftHanded then reverse else identity
62 63 64
            -- SB.searchBar {session, databases: allDatabases}


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


76 77
divDropdownLeft :: R2.Component ()
divDropdownLeft = R.createElement divDropdownLeftCpt
78

79 80 81 82 83 84
divDropdownLeftCpt :: R.Component ()
divDropdownLeftCpt = R.hooksComponentWithModule thisModule "divDropdownLeft" cpt
  where
    cpt {} _ = do
      show <- R.useState' false

85
      pure $ H.li { className: "nav-item dropdown" } [
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
          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/"
104
              , icon  : "fa fa-bullhorn"
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
              , 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"
123
              , icon  : "fa fa-book"
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
              , 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"
141
              , icon  : "fa fa-question"
142 143 144 145 146 147 148 149 150 151 152 153
              , text  : "About"
              }
      ]
    ] -- ===========================================================

type MenuButtonProps = (
    element :: LiNav
  , show :: R.State Boolean
  )

menuButton :: R2.Component MenuButtonProps
menuButton = R.createElement menuButtonCpt
154
  where
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    menuButtonCpt :: R.Component MenuButtonProps
    menuButtonCpt = R.hooksComponentWithModule thisModule "menuButton" cpt

    cpt { element: LiNav { title, href, icon, text }, show: (_ /\ setShow) } _ = do
      pure $ H.a { className: "dropdown-toggle navbar-text"
                -- , data: {toggle: "dropdown"}
                , href, title
                , on: { click: \_ -> setShow $ not }
                , role: "button" } [
          H.span { aria: {hidden : true}, className: icon } []
        , H.text (" " <> text)
        ]

-- | Menu in the sidebar, syntactic sugar
type MenuElementsProps = (
    elements :: Array (Array LiNav)
  , show :: R.State Boolean
  )
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187
menuElements :: R2.Component MenuElementsProps
menuElements = R.createElement menuElementsCpt
  where
    menuElementsCpt :: R.Component MenuElementsProps
    menuElementsCpt = R.hooksComponentWithModule thisModule "menuElements" cpt

    cpt { show: false /\ _ } _ = do
      pure $ H.div {} []
    cpt { elements, show: (true /\ setShow) } _ = do
      pure $ H.ul { className: "dropdown-menu"
                  , on: { click: setShow $ const false }
                  , style: { display: "block" } } $ intercalate divider $ map (map liNav) elements
      where
        divider :: Array R.Element
188
        divider = [H.li {className: "dropdown-divider"} []]
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

-- | 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'
             }
210 211 212 213 214 215 216
      ) = H.li { className: "dropdown-item" } [
            H.a { tabIndex: (-1)
                , target: "blank"
                , title: title'
                , href: href'
                } [ H.span { className: icon' } []
                  , H.text $ " " <> text'
217
                  ]
218
            ]
219 220 221 222 223 224


type HandedChooserProps = (
  handed :: R.State Handed
  )

225 226
handedChooser :: R2.Component HandedChooserProps
handedChooser = R.createElement handedChooserCpt
227 228 229 230 231

handedChooserCpt :: R.Component HandedChooserProps
handedChooserCpt = R.hooksComponentWithModule thisModule "handedChooser" cpt
  where
    cpt { handed } _ = do
232 233
      pure $ H.a { className: "nav-link" } [
        H.span { className: handedClass handed
234
               , on: { click: onClick handed } } []
235 236 237 238 239 240 241 242
        ]

    handedClass (LeftHanded  /\ _) = "fa fa-hand-o-left"
    handedClass (RightHanded /\ _) = "fa fa-hand-o-right"

    onClick (_ /\ setHanded) = setHanded $ \h -> case h of
      LeftHanded  -> RightHanded
      RightHanded -> LeftHanded