Ensure weekday is updated
This ensures us that our view is consistent within ~1 minute of reality.
This commit is contained in:
parent
7d425de48d
commit
487232d1aa
2 changed files with 8 additions and 2 deletions
|
@ -4,11 +4,13 @@ import Browser
|
||||||
import Habits
|
import Habits
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import State
|
import State
|
||||||
|
import Time
|
||||||
|
|
||||||
|
|
||||||
subscriptions : State.Model -> Sub State.Msg
|
subscriptions : State.Model -> Sub State.Msg
|
||||||
subscriptions model =
|
subscriptions model =
|
||||||
Sub.none
|
-- once per minute
|
||||||
|
Time.every (1000 * 60) (\_ -> State.MaybeAdjustWeekday)
|
||||||
|
|
||||||
|
|
||||||
view : State.Model -> Html State.Msg
|
view : State.Model -> Html State.Msg
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Msg
|
||||||
| SetView View
|
| SetView View
|
||||||
| ReceiveDate Date.Date
|
| ReceiveDate Date.Date
|
||||||
| ToggleHabit Int
|
| ToggleHabit Int
|
||||||
|
| MaybeAdjustWeekday
|
||||||
|
|
||||||
|
|
||||||
type View
|
type View
|
||||||
|
@ -65,7 +66,7 @@ update msg ({ completed } as model) =
|
||||||
)
|
)
|
||||||
|
|
||||||
ReceiveDate x ->
|
ReceiveDate x ->
|
||||||
( { model | dayOfWeek = Just Sun }, Cmd.none )
|
( { model | dayOfWeek = Just (Date.weekday x) }, Cmd.none )
|
||||||
|
|
||||||
ToggleHabit i ->
|
ToggleHabit i ->
|
||||||
( { model
|
( { model
|
||||||
|
@ -78,3 +79,6 @@ update msg ({ completed } as model) =
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MaybeAdjustWeekday ->
|
||||||
|
( model, Date.today |> Task.perform ReceiveDate )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue