Better timezone
This commit is contained in:
parent
e5c9bde291
commit
a6c651bdd2
1
elm.json
1
elm.json
|
@ -15,6 +15,7 @@
|
|||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"jims/html-parser": "1.0.0",
|
||||
"justinmimbs/timezone-data": "3.0.3",
|
||||
"mdgriffith/elm-ui": "1.1.8",
|
||||
"rtfeldman/elm-iso8601-date-strings": "1.1.3"
|
||||
},
|
||||
|
|
21
src/Core.elm
21
src/Core.elm
|
@ -10,6 +10,7 @@ import Http
|
|||
import Ports
|
||||
import Task
|
||||
import Time
|
||||
import TimeZone
|
||||
import Twitch
|
||||
import Url
|
||||
|
||||
|
@ -44,6 +45,7 @@ type Msg
|
|||
| UrlReceived Url.Url
|
||||
| UrlRequested Browser.UrlRequest
|
||||
| SizeReceived Int Int
|
||||
| TimeZoneReceivedResult (Result TimeZone.Error ( String, Time.Zone ))
|
||||
| TimeZoneReceived Time.Zone
|
||||
| HoverPlaylist Twitch.Playlist
|
||||
| HoverVideo Twitch.Video
|
||||
|
@ -55,7 +57,9 @@ init : { width : Int, height : Int } -> Url.Url -> Nav.Key -> ( FullModel, Cmd M
|
|||
init { width, height } url key =
|
||||
( Unloaded (Element.classifyDevice { width = width, height = height }) url key Time.utc
|
||||
, Cmd.batch
|
||||
[ Task.perform TimeZoneReceived Time.here
|
||||
[ Task.attempt TimeZoneReceivedResult TimeZone.getZone
|
||||
|
||||
-- Task.perform TimeZoneReceived Time.here
|
||||
, Twitch.fetchPlaylists resultToMsg
|
||||
]
|
||||
)
|
||||
|
@ -88,6 +92,18 @@ update msg model =
|
|||
( TimeZoneReceived z, Unloaded d u k _ ) ->
|
||||
( Unloaded d u k z, Cmd.none )
|
||||
|
||||
( TimeZoneReceived z, Loaded m ) ->
|
||||
( Loaded { m | zone = z }, Cmd.none )
|
||||
|
||||
( TimeZoneReceivedResult (Ok ( _, zone )), Unloaded d u k _ ) ->
|
||||
( Unloaded d u k zone, Cmd.none )
|
||||
|
||||
( TimeZoneReceivedResult (Ok ( _, zone )), Loaded m ) ->
|
||||
( Loaded { m | zone = zone }, Cmd.none )
|
||||
|
||||
( TimeZoneReceivedResult (Err _), _ ) ->
|
||||
( model, Task.perform TimeZoneReceived Time.here )
|
||||
|
||||
( TimeReceived p, Loaded m ) ->
|
||||
( Loaded { m | time = p }, Cmd.none )
|
||||
|
||||
|
@ -121,9 +137,6 @@ update msg model =
|
|||
Video p v _ ->
|
||||
( Loaded { m | page = Video p v Nothing }, 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
|
||||
|
|
Loading…
Reference in New Issue