Default to "today"

This commit is contained in:
Anthony Cicchetti 2019-09-29 16:15:48 -04:00
parent 85b0ec9e56
commit 2fa16a8f27

View file

@ -72,6 +72,7 @@ type alias Score =
type Msg type Msg
= NewDate String = NewDate String
| NewEntries (Result Http.Error (List Entry)) | NewEntries (Result Http.Error (List Entry))
| ReceiveDate Date.Date
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
@ -92,11 +93,19 @@ update msg model =
NewEntries (Err err) -> NewEntries (Err err) ->
( model, Cmd.none ) ( model, Cmd.none )
ReceiveDate date ->
( model, getScores (Date.format "YYYY-MM-dd" date) )
--- COMMANDS --- COMMANDS
getTodayScores : Cmd Msg
getTodayScores =
Task.perform ReceiveDate Date.today
getScores : String -> Cmd Msg getScores : String -> Cmd Msg
getScores newDate = getScores newDate =
Http.request Http.request
@ -166,7 +175,7 @@ subscriptions model =
init : () -> ( Model, Cmd Msg ) init : () -> ( Model, Cmd Msg )
init _ = init _ =
( Model "2019-09-29" [] Nothing "" ( Model "2019-09-29" [] Nothing ""
, getScores "2019-09-29" , getTodayScores
) )