Use Maybe.withDefault some more. Do not show anything before finishing loading data.
This commit is contained in:
parent
c237d4ecc7
commit
974694bd5f
|
@ -60,13 +60,10 @@ eventDecoder =
|
||||||
dateDecoder : Decoder Date
|
dateDecoder : Decoder Date
|
||||||
dateDecoder =
|
dateDecoder =
|
||||||
let
|
let
|
||||||
unpacked x =
|
unpacked isoString =
|
||||||
case Date.Extra.fromIsoString x of
|
isoString
|
||||||
Just value ->
|
|> Date.Extra.fromIsoString
|
||||||
value
|
|> Maybe.withDefault (Date.Extra.fromParts 1970 Jan 1 0 0 0 0)
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
Date.Extra.fromParts 1970 Jan 1 0 0 0 0
|
|
||||||
in
|
in
|
||||||
Json.Decode.map unpacked string
|
Json.Decode.map unpacked string
|
||||||
|
|
||||||
|
@ -108,7 +105,7 @@ eventTypeDecoder =
|
||||||
|> required "light_text" bool
|
|> required "light_text" bool
|
||||||
|
|
||||||
|
|
||||||
initDataDecoder : Decoder (Flags -> Filter -> Location -> Route -> Model)
|
initDataDecoder : Decoder (Flags -> Filter -> Location -> Route -> Bool -> Model)
|
||||||
initDataDecoder =
|
initDataDecoder =
|
||||||
decode Model
|
decode Model
|
||||||
|> required "days" (list dayDecoder)
|
|> required "days" (list dayDecoder)
|
||||||
|
|
|
@ -12,7 +12,6 @@ import Views exposing (view)
|
||||||
|
|
||||||
-- External modules
|
-- External modules
|
||||||
|
|
||||||
import Html.Lazy exposing (lazy)
|
|
||||||
import WebSocket exposing (listen)
|
import WebSocket exposing (listen)
|
||||||
import Navigation exposing (Location)
|
import Navigation exposing (Location)
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ main =
|
||||||
Navigation.programWithFlags
|
Navigation.programWithFlags
|
||||||
OnLocationChange
|
OnLocationChange
|
||||||
{ init = init
|
{ init = init
|
||||||
, view = lazy view
|
, view = view
|
||||||
, update = update
|
, update = update
|
||||||
, subscriptions = subscriptions
|
, subscriptions = subscriptions
|
||||||
}
|
}
|
||||||
|
@ -32,13 +31,13 @@ init : Flags -> Location -> ( Model, Cmd Msg )
|
||||||
init flags location =
|
init flags location =
|
||||||
let
|
let
|
||||||
currentRoute =
|
currentRoute =
|
||||||
parseLocation (Debug.log "location" location)
|
parseLocation location
|
||||||
|
|
||||||
emptyFilter =
|
emptyFilter =
|
||||||
Filter [] [] []
|
Filter [] [] []
|
||||||
|
|
||||||
model =
|
model =
|
||||||
Model [] [] [] [] [] flags emptyFilter location currentRoute
|
Model [] [] [] [] [] flags emptyFilter location currentRoute False
|
||||||
in
|
in
|
||||||
model ! [ sendInitMessage flags.camp_slug flags.websocket_server ]
|
model ! [ sendInitMessage flags.camp_slug flags.websocket_server ]
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ type alias Model =
|
||||||
, filter : Filter
|
, filter : Filter
|
||||||
, location : Location
|
, location : Location
|
||||||
, route : Route
|
, route : Route
|
||||||
|
, dataLoaded : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,5 @@ matchers =
|
||||||
|
|
||||||
parseLocation : Location -> Route
|
parseLocation : Location -> Route
|
||||||
parseLocation location =
|
parseLocation location =
|
||||||
case parseHash matchers location of
|
parseHash matchers location
|
||||||
Just route ->
|
|> Maybe.withDefault NotFoundRoute
|
||||||
route
|
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
NotFoundRoute
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ update msg model =
|
||||||
"init" ->
|
"init" ->
|
||||||
case Json.Decode.decodeString initDataDecoder str of
|
case Json.Decode.decodeString initDataDecoder str of
|
||||||
Ok m ->
|
Ok m ->
|
||||||
m model.flags model.filter model.location model.route
|
m model.flags model.filter model.location model.route True
|
||||||
|
|
||||||
Err error ->
|
Err error ->
|
||||||
model
|
model
|
||||||
|
|
|
@ -23,6 +23,8 @@ import Date.Extra
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
|
case model.dataLoaded of
|
||||||
|
True ->
|
||||||
div []
|
div []
|
||||||
[ dayPicker model
|
[ dayPicker model
|
||||||
, hr [] []
|
, hr [] []
|
||||||
|
@ -36,12 +38,10 @@ view model =
|
||||||
DayRoute dayIso ->
|
DayRoute dayIso ->
|
||||||
let
|
let
|
||||||
day =
|
day =
|
||||||
case (List.head (List.filter (\x -> (Date.Extra.toFormattedString "y-MM-dd" x.date) == dayIso) model.days)) of
|
model.days
|
||||||
Just day ->
|
|> List.filter (\x -> (Date.Extra.toFormattedString "y-MM-dd" x.date) == dayIso)
|
||||||
day
|
|> List.head
|
||||||
|
|> Maybe.withDefault (Day "" (Date.Extra.fromParts 1970 Jan 1 0 0 0 0) "")
|
||||||
Nothing ->
|
|
||||||
Day "" (Date.Extra.fromParts 1970 Jan 1 0 0 0 0) ""
|
|
||||||
in
|
in
|
||||||
dayView day model
|
dayView day model
|
||||||
|
|
||||||
|
@ -51,3 +51,6 @@ view model =
|
||||||
NotFoundRoute ->
|
NotFoundRoute ->
|
||||||
div [] [ text "Not found!" ]
|
div [] [ text "Not found!" ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
False ->
|
||||||
|
h4 [] [ text "Loading schedule..." ]
|
||||||
|
|
|
@ -146,24 +146,19 @@ renderGroup offset group =
|
||||||
List.map findLefts sortedGroup
|
List.map findLefts sortedGroup
|
||||||
|
|
||||||
numberInGroup =
|
numberInGroup =
|
||||||
case List.maximum (List.map (\( _, left ) -> left) lefts) of
|
lefts
|
||||||
Just num ->
|
|> List.map (\( _, left ) -> left)
|
||||||
num
|
|> List.maximum
|
||||||
|
|> Maybe.withDefault 1
|
||||||
Nothing ->
|
|
||||||
1
|
|
||||||
|
|
||||||
fixedLefts =
|
fixedLefts =
|
||||||
if numberInGroup == 0 then
|
if numberInGroup == 0 then
|
||||||
List.map
|
List.map
|
||||||
(\( instance, x ) ->
|
(\( instance, x ) ->
|
||||||
( instance
|
( instance
|
||||||
, case List.Extra.elemIndex ( instance, x ) lefts of
|
, lefts
|
||||||
Just index ->
|
|> List.Extra.elemIndex ( instance, x )
|
||||||
index
|
|> Maybe.withDefault 0
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
0
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
lefts
|
lefts
|
||||||
|
@ -171,12 +166,10 @@ renderGroup offset group =
|
||||||
lefts
|
lefts
|
||||||
|
|
||||||
fixedNumberInGroup =
|
fixedNumberInGroup =
|
||||||
case List.maximum (List.map (\( _, left ) -> left) fixedLefts) of
|
fixedLefts
|
||||||
Just num ->
|
|> List.map (\( _, left ) -> left)
|
||||||
num
|
|> List.maximum
|
||||||
|
|> Maybe.withDefault 1
|
||||||
Nothing ->
|
|
||||||
1
|
|
||||||
in
|
in
|
||||||
div
|
div
|
||||||
[ style
|
[ style
|
||||||
|
|
|
@ -19,13 +19,12 @@ eventDetailView : EventSlug -> Model -> Html Msg
|
||||||
eventDetailView eventSlug model =
|
eventDetailView eventSlug model =
|
||||||
let
|
let
|
||||||
event =
|
event =
|
||||||
case List.head (List.filter (\e -> e.slug == eventSlug) model.events) of
|
model.events
|
||||||
Just event ->
|
|> List.filter (\e -> e.slug == eventSlug)
|
||||||
event
|
|> List.head
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
{ title = "", slug = "", abstract = "", speakers = [], videoRecording = False, videoUrl = "" }
|
|
||||||
in
|
in
|
||||||
|
case event of
|
||||||
|
Just event ->
|
||||||
div [ class "row" ]
|
div [ class "row" ]
|
||||||
[ div [ class "col-sm-9" ]
|
[ div [ class "col-sm-9" ]
|
||||||
[ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ]
|
[ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ]
|
||||||
|
@ -49,6 +48,18 @@ eventDetailView eventSlug model =
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
div [ class "row" ]
|
||||||
|
[ text
|
||||||
|
(case model.dataLoaded of
|
||||||
|
True ->
|
||||||
|
"Event not found."
|
||||||
|
|
||||||
|
False ->
|
||||||
|
"Loading..."
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
videoRecordingSidebar : Event -> Html Msg
|
videoRecordingSidebar : Event -> Html Msg
|
||||||
videoRecordingSidebar event =
|
videoRecordingSidebar event =
|
||||||
|
|
Loading…
Reference in a new issue