about summary refs log tree commit diff
path: root/users/wpcarro/assessments/tt/client/src/Common.elm
blob: 63ba97b794ac9ec970a9fa4e7fead47e9a345314 (plain) (blame)
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
module Common exposing (..)

import Html exposing (..)
import Maybe.Extra as ME
import State
import UI
import Utils


allErrors : State.Model -> Html State.Msg
allErrors model =
    div []
        (State.allErrors
            model
            |> List.map
                (\( mError, title ) ->
                    case mError of
                        Nothing ->
                            text ""

                        Just err ->
                            UI.errorBanner
                                { title = title
                                , body = Utils.explainHttpError err
                                }
                )
        )


withSession : State.Model -> (State.Session -> Html State.Msg) -> Html State.Msg
withSession model renderWithSession =
    case model.session of
        Nothing ->
            div [] [ UI.paragraph "You need a valid session to view this page. Please attempt to log in." ]

        Just session ->
            renderWithSession session