Fix timezone

This commit is contained in:
Thomas Forgione 2020-10-15 16:47:10 +02:00
parent 8c10e99cca
commit bf1d35c179
2 changed files with 19 additions and 8 deletions

View File

@ -7,13 +7,14 @@ import Dict exposing (Dict)
import Element import Element
import Http import Http
import Ports import Ports
import Task
import Time import Time
import Twitch import Twitch
import Url import Url
type FullModel type FullModel
= Unloaded Element.Device Url.Url Nav.Key = Unloaded Element.Device Url.Url Nav.Key Time.Zone
| Loaded Model | Loaded Model
@ -34,19 +35,23 @@ type Page
type Msg type Msg
= Noop = Noop
| PlaylistsReceived ( List Twitch.Playlist, Time.Zone ) | PlaylistsReceived (List Twitch.Playlist)
| HomeClicked | HomeClicked
| PlaylistClicked Twitch.Playlist | PlaylistClicked Twitch.Playlist
| VideoClicked Twitch.Playlist Twitch.Video | VideoClicked Twitch.Playlist Twitch.Video
| UrlReceived Url.Url | UrlReceived Url.Url
| UrlRequested Browser.UrlRequest | UrlRequested Browser.UrlRequest
| SizeReceived Int Int | SizeReceived Int Int
| TimeZoneReceived Time.Zone
init : { width : Int, height : Int } -> Url.Url -> Nav.Key -> ( FullModel, Cmd Msg ) init : { width : Int, height : Int } -> Url.Url -> Nav.Key -> ( FullModel, Cmd Msg )
init { width, height } url key = init { width, height } url key =
( Unloaded (Element.classifyDevice { width = width, height = height }) url key ( Unloaded (Element.classifyDevice { width = width, height = height }) url key Time.utc
, Twitch.fetchPlaylists resultToMsg , Cmd.batch
[ Task.perform TimeZoneReceived Time.here
, Twitch.fetchPlaylists resultToMsg
]
) )
@ -54,7 +59,7 @@ resultToMsg : Result Http.Error (List Twitch.Playlist) -> Msg
resultToMsg result = resultToMsg result =
case result of case result of
Ok o -> Ok o ->
PlaylistsReceived ( o, Time.utc ) PlaylistsReceived o
Err _ -> Err _ ->
Noop Noop
@ -71,12 +76,18 @@ update msg model =
( Noop, _ ) -> ( Noop, _ ) ->
( model, Cmd.none ) ( 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 ) -> ( SizeReceived w h, Loaded m ) ->
( Loaded { m | device = Element.classifyDevice { width = w, height = h } } ( Loaded { m | device = Element.classifyDevice { width = w, height = h } }
, Cmd.none , Cmd.none
) )
( PlaylistsReceived ( playlists, zone ), Unloaded device url key ) -> ( PlaylistsReceived playlists, Unloaded device url key zone ) ->
update update
(UrlReceived url) (UrlReceived url)
(Loaded { key = key, playlists = playlists, zone = zone, page = Home, device = device }) (Loaded { key = key, playlists = playlists, zone = zone, page = Home, device = device })

View File

@ -24,7 +24,7 @@ view model =
let let
element = element =
case model of case model of
Core.Unloaded _ _ _ -> Core.Unloaded _ _ _ _ ->
Element.el [ Element.padding 10, Element.centerX ] spinner Element.el [ Element.padding 10, Element.centerX ] spinner
Core.Loaded m -> Core.Loaded m ->
@ -48,7 +48,7 @@ view model =
title : Core.FullModel -> String title : Core.FullModel -> String
title model = title model =
case model of case model of
Core.Unloaded _ _ _ -> Core.Unloaded _ _ _ _ ->
Consts.url Consts.url
Core.Loaded m -> Core.Loaded m ->