Use Maybe.withDefault some more. Do not show anything before finishing loading data.

This commit is contained in:
Vidir Valberg Gudmundsson 2017-07-23 18:30:27 +02:00
parent c237d4ecc7
commit 974694bd5f
8 changed files with 86 additions and 86 deletions

View file

@ -60,13 +60,10 @@ eventDecoder =
dateDecoder : Decoder Date
dateDecoder =
let
unpacked x =
case Date.Extra.fromIsoString x of
Just value ->
value
Nothing ->
Date.Extra.fromParts 1970 Jan 1 0 0 0 0
unpacked isoString =
isoString
|> Date.Extra.fromIsoString
|> Maybe.withDefault (Date.Extra.fromParts 1970 Jan 1 0 0 0 0)
in
Json.Decode.map unpacked string
@ -108,7 +105,7 @@ eventTypeDecoder =
|> required "light_text" bool
initDataDecoder : Decoder (Flags -> Filter -> Location -> Route -> Model)
initDataDecoder : Decoder (Flags -> Filter -> Location -> Route -> Bool -> Model)
initDataDecoder =
decode Model
|> required "days" (list dayDecoder)

View file

@ -12,7 +12,6 @@ import Views exposing (view)
-- External modules
import Html.Lazy exposing (lazy)
import WebSocket exposing (listen)
import Navigation exposing (Location)
@ -22,7 +21,7 @@ main =
Navigation.programWithFlags
OnLocationChange
{ init = init
, view = lazy view
, view = view
, update = update
, subscriptions = subscriptions
}
@ -32,13 +31,13 @@ init : Flags -> Location -> ( Model, Cmd Msg )
init flags location =
let
currentRoute =
parseLocation (Debug.log "location" location)
parseLocation location
emptyFilter =
Filter [] [] []
model =
Model [] [] [] [] [] flags emptyFilter location currentRoute
Model [] [] [] [] [] flags emptyFilter location currentRoute False
in
model ! [ sendInitMessage flags.camp_slug flags.websocket_server ]

View file

@ -28,6 +28,7 @@ type alias Model =
, filter : Filter
, location : Location
, route : Route
, dataLoaded : Bool
}

View file

@ -41,9 +41,5 @@ matchers =
parseLocation : Location -> Route
parseLocation location =
case parseHash matchers location of
Just route ->
route
Nothing ->
NotFoundRoute
parseHash matchers location
|> Maybe.withDefault NotFoundRoute

View file

@ -34,7 +34,7 @@ update msg model =
"init" ->
case Json.Decode.decodeString initDataDecoder str of
Ok m ->
m model.flags model.filter model.location model.route
m model.flags model.filter model.location model.route True
Err error ->
model

View file

@ -23,31 +23,34 @@ import Date.Extra
view : Model -> Html Msg
view model =
div []
[ dayPicker model
, hr [] []
, case model.route of
OverviewRoute ->
scheduleOverviewView model
case model.dataLoaded of
True ->
div []
[ dayPicker model
, hr [] []
, case model.route of
OverviewRoute ->
scheduleOverviewView model
OverviewFilteredRoute _ ->
scheduleOverviewView model
OverviewFilteredRoute _ ->
scheduleOverviewView model
DayRoute dayIso ->
let
day =
case (List.head (List.filter (\x -> (Date.Extra.toFormattedString "y-MM-dd" x.date) == dayIso) model.days)) of
Just day ->
day
DayRoute dayIso ->
let
day =
model.days
|> List.filter (\x -> (Date.Extra.toFormattedString "y-MM-dd" x.date) == dayIso)
|> List.head
|> Maybe.withDefault (Day "" (Date.Extra.fromParts 1970 Jan 1 0 0 0 0) "")
in
dayView day model
Nothing ->
Day "" (Date.Extra.fromParts 1970 Jan 1 0 0 0 0) ""
in
dayView day model
EventRoute eventSlug ->
eventDetailView eventSlug model
EventRoute eventSlug ->
eventDetailView eventSlug model
NotFoundRoute ->
div [] [ text "Not found!" ]
]
NotFoundRoute ->
div [] [ text "Not found!" ]
]
False ->
h4 [] [ text "Loading schedule..." ]

View file

@ -146,24 +146,19 @@ renderGroup offset group =
List.map findLefts sortedGroup
numberInGroup =
case List.maximum (List.map (\( _, left ) -> left) lefts) of
Just num ->
num
Nothing ->
1
lefts
|> List.map (\( _, left ) -> left)
|> List.maximum
|> Maybe.withDefault 1
fixedLefts =
if numberInGroup == 0 then
List.map
(\( instance, x ) ->
( instance
, case List.Extra.elemIndex ( instance, x ) lefts of
Just index ->
index
Nothing ->
0
, lefts
|> List.Extra.elemIndex ( instance, x )
|> Maybe.withDefault 0
)
)
lefts
@ -171,12 +166,10 @@ renderGroup offset group =
lefts
fixedNumberInGroup =
case List.maximum (List.map (\( _, left ) -> left) fixedLefts) of
Just num ->
num
Nothing ->
1
fixedLefts
|> List.map (\( _, left ) -> left)
|> List.maximum
|> Maybe.withDefault 1
in
div
[ style

View file

@ -19,35 +19,46 @@ eventDetailView : EventSlug -> Model -> Html Msg
eventDetailView eventSlug model =
let
event =
case List.head (List.filter (\e -> e.slug == eventSlug) model.events) of
Just event ->
event
Nothing ->
{ title = "", slug = "", abstract = "", speakers = [], videoRecording = False, videoUrl = "" }
model.events
|> List.filter (\e -> e.slug == eventSlug)
|> List.head
in
div [ class "row" ]
[ div [ class "col-sm-9" ]
[ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ]
[ i [ classList [ ( "fa", True ), ( "fa-chevron-left", True ) ] ] []
, text " Back"
case event of
Just event ->
div [ class "row" ]
[ div [ class "col-sm-9" ]
[ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ]
[ i [ classList [ ( "fa", True ), ( "fa-chevron-left", True ) ] ] []
, text " Back"
]
, h4 [] [ text event.title ]
, p [] [ Markdown.toHtml [] event.abstract ]
, hr [] []
, eventInstancesList eventSlug model.eventInstances
]
, div
[ classList
[ ( "col-sm-3", True )
, ( "schedule-sidebar", True )
, ( "sticky", True )
]
]
[ videoRecordingSidebar event
, speakerSidebar event.speakers
]
]
, h4 [] [ text event.title ]
, p [] [ Markdown.toHtml [] event.abstract ]
, hr [] []
, eventInstancesList eventSlug model.eventInstances
]
, div
[ classList
[ ( "col-sm-3", True )
, ( "schedule-sidebar", True )
, ( "sticky", True )
Nothing ->
div [ class "row" ]
[ text
(case model.dataLoaded of
True ->
"Event not found."
False ->
"Loading..."
)
]
]
[ videoRecordingSidebar event
, speakerSidebar event.speakers
]
]
videoRecordingSidebar : Event -> Html Msg