implement NotAsked, Error and empty search result view (#28)

fixes #25
fixes #26
fixes #27
This commit is contained in:
Rok Garbas 2020-05-12 00:00:23 +02:00 committed by GitHub
parent 645813cbd1
commit ec4c23f295
Failed to generate hash of commit

View file

@ -22,6 +22,7 @@ import Html
, em , em
, form , form
, h1 , h1
, h4
, input , input
, li , li
, option , option
@ -265,42 +266,65 @@ view path title model viewSuccess outMsg =
] ]
, case model.result of , case model.result of
RemoteData.NotAsked -> RemoteData.NotAsked ->
div [] [ text "NotAsked" ] div [] [ text "" ]
RemoteData.Loading -> RemoteData.Loading ->
div [] [ text "Loading" ] div [] [ text "Loading" ]
RemoteData.Success result -> RemoteData.Success result ->
div [] if result.hits.total.value == 0 then
[ p [] div []
[ em [] [ h4 [] [ text <| "No " ++ path ++ " found!" ]
[ text ]
("Showing results "
++ String.fromInt model.from else
++ "-" div []
++ String.fromInt [ p []
(if model.from + model.size > result.hits.total.value then [ em []
result.hits.total.value [ text
("Showing results "
else ++ String.fromInt model.from
model.from + model.size ++ "-"
) ++ String.fromInt
++ " of " (if model.from + model.size > result.hits.total.value then
++ String.fromInt result.hits.total.value result.hits.total.value
++ "."
) else
] model.from + model.size
)
++ " of "
++ String.fromInt result.hits.total.value
++ "."
)
]
]
, viewPager outMsg model result path
, viewSuccess model.showDetailsFor result
, viewPager outMsg model result path
] ]
, viewPager outMsg model result path
, viewSuccess model.showDetailsFor result
, viewPager outMsg model result path
]
RemoteData.Failure error -> RemoteData.Failure error ->
div [] let
[ text "Error!" ( errorTitle, errorMessage ) =
case error of
Http.BadUrl text ->
( "Bad Url!", text )
--, pre [] [ text (Debug.toString error) ] Http.Timeout ->
( "Timeout!", "Request to the server timeout." )
Http.NetworkError ->
( "Network Error!", "Please check your network connection." )
Http.BadStatus code ->
( "Bad Status", "Server returned " ++ String.fromInt code )
Http.BadBody text ->
( "Bad Body", text )
in
div [ class "alert alert-error" ]
[ h4 [] [ text errorTitle ]
, text errorMessage
] ]
] ]