aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/View/Header.elm
blob: 2edde2739bee6a5c45bd3c4b758d1d3d456a814d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
53
54
55
56
57
58
59
60
61
module View.Header
  ( renderHeader
  ) where

import Signal exposing (Address)
import Dict

import TransitRouter

import Route exposing (..)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)

import Model exposing (Model)
import Model.Translations exposing (getMessage)
import Action exposing (..)
import Model.View exposing (..)

import View.Icon exposing (renderIcon)
import View.Click exposing (clickTo)

renderHeader : Address Action -> Model -> Html
renderHeader address model =
  let item = specialItem True ""
      specialItem showCurrent additionalClasses route name =
        a
          ( [ classList
              [ ("item", True)
              , (additionalClasses, True)
              , ("current", showCurrent && TransitRouter.getRoute model == route)
              ]
            ] ++ clickTo route
          )
          [ text (getMessage name model.translations)
          ]
  in
      header
        []
        ( case model.view of
            LoggedInView { me, users } ->
              [ specialItem True "title" Home "SharedCost"
              , item Income "Income"
              , item Stat "Statistics"
              , button
                  [ class "signOut item"
                  , onClick address SignOut
                  ]
                  [ renderIcon "power-off" ]
              , div
                  [ class "name" ]
                  [ Dict.get me users
                      |> Maybe.map .name
                      |> Maybe.withDefault ""
                      |> text
                  ]
              ]
            _ ->
              [specialItem False "title" Home "SharedCost"]
        )