From bf1d35c179357929f63a03c41b54bb841683e9fa Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 15 Oct 2020 16:47:10 +0200 Subject: [PATCH] Fix timezone --- src/Core.elm | 23 +++++++++++++++++------ src/Views.elm | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) 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 ->