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