diff --git a/src/Core.elm b/src/Core.elm index 8753589..7e19c5f 100644 --- a/src/Core.elm +++ b/src/Core.elm @@ -7,13 +7,14 @@ import Dict exposing (Dict) import Element import Http import Ports +import Task import Time import Twitch import Url type FullModel - = Unloaded Element.Device Url.Url Nav.Key + = Unloaded Element.Device Url.Url Nav.Key Time.Zone | Loaded Model @@ -34,19 +35,23 @@ type Page type Msg = Noop - | PlaylistsReceived ( List Twitch.Playlist, Time.Zone ) + | PlaylistsReceived (List Twitch.Playlist) | HomeClicked | PlaylistClicked Twitch.Playlist | VideoClicked Twitch.Playlist Twitch.Video | UrlReceived Url.Url | UrlRequested Browser.UrlRequest | SizeReceived Int Int + | TimeZoneReceived Time.Zone init : { width : Int, height : Int } -> Url.Url -> Nav.Key -> ( FullModel, Cmd Msg ) init { width, height } url key = - ( Unloaded (Element.classifyDevice { width = width, height = height }) url key - , Twitch.fetchPlaylists resultToMsg + ( Unloaded (Element.classifyDevice { width = width, height = height }) url key Time.utc + , Cmd.batch + [ Task.perform TimeZoneReceived Time.here + , Twitch.fetchPlaylists resultToMsg + ] ) @@ -54,7 +59,7 @@ resultToMsg : Result Http.Error (List Twitch.Playlist) -> Msg resultToMsg result = case result of Ok o -> - PlaylistsReceived ( o, Time.utc ) + PlaylistsReceived o Err _ -> Noop @@ -71,12 +76,18 @@ update msg model = ( Noop, _ ) -> ( model, Cmd.none ) + ( TimeZoneReceived z, Unloaded d u k _ ) -> + ( Unloaded d u k z, Cmd.none ) + + ( TimeZoneReceived z, Loaded m ) -> + ( Loaded { m | zone = z }, Cmd.none ) + ( SizeReceived w h, Loaded m ) -> ( Loaded { m | device = Element.classifyDevice { width = w, height = h } } , Cmd.none ) - ( PlaylistsReceived ( playlists, zone ), Unloaded device url key ) -> + ( PlaylistsReceived playlists, Unloaded device url key zone ) -> update (UrlReceived url) (Loaded { key = key, playlists = playlists, zone = zone, page = Home, device = device }) diff --git a/src/Views.elm b/src/Views.elm index ec129f0..a00b703 100644 --- a/src/Views.elm +++ b/src/Views.elm @@ -24,7 +24,7 @@ view model = let element = case model of - Core.Unloaded _ _ _ -> + Core.Unloaded _ _ _ _ -> Element.el [ Element.padding 10, Element.centerX ] spinner Core.Loaded m -> @@ -48,7 +48,7 @@ view model = title : Core.FullModel -> String title model = case model of - Core.Unloaded _ _ _ -> + Core.Unloaded _ _ _ _ -> Consts.url Core.Loaded m ->