-
Notifications
You must be signed in to change notification settings - Fork 5
/
Utils.elm
57 lines (39 loc) · 1.13 KB
/
Utils.elm
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
module Utils exposing (disabledIfLoading, httpErrorToStr, maybe, maybeIsNothing, maybeToList, remoteDataError)
import Html as H
import Html.Attributes as HA
import Html.Events as HE
import Http
import Json.Decode
import RemoteData
disabledIfLoading : RemoteData.RemoteData e a -> H.Attribute msm
disabledIfLoading m =
HA.disabled (RemoteData.isLoading m)
remoteDataError : RemoteData.RemoteData e a -> Maybe e
remoteDataError rd =
case rd of
RemoteData.Failure e ->
Just e
_ ->
Nothing
maybe : b -> (a -> b) -> Maybe a -> b
maybe z f =
Maybe.map f >> Maybe.withDefault z
maybeIsNothing : Maybe a -> Bool
maybeIsNothing =
maybe True (always False)
maybeToList : Maybe a -> List a
maybeToList =
maybe [] List.singleton
httpErrorToStr : Http.Error -> String
httpErrorToStr err =
case err of
Http.BadUrl s ->
"Bad URL: " ++ s
Http.Timeout ->
"Timeout"
Http.NetworkError ->
"NetworkError"
Http.BadStatus s ->
"Bad Status" ++ String.fromInt s
Http.BadBody s ->
"Bad Body" ++ s