Support time

This commit is contained in:
2020-10-04 21:31:16 +02:00
parent 42de337746
commit a1ccbbefa3
3 changed files with 57 additions and 5 deletions
+42 -3
View File
@@ -2,6 +2,7 @@ module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, subscriptio
import Browser.Events as Events
import Browser.Navigation as Nav
import Dict exposing (Dict)
import Element
import Ports
import Task
@@ -85,9 +86,32 @@ update msg model =
( UrlReceived url, Loaded m ) ->
let
split =
String.split "/" (Maybe.withDefault "" url.fragment)
splits =
String.split "?" (Maybe.withDefault "" url.fragment)
( split, args ) =
case splits of
h1 :: h2 :: _ ->
( String.split "/" h1, parseQueryString h2 )
h1 :: _ ->
( String.split "/" h1, Dict.empty )
_ ->
( [], Dict.empty )
time =
case Maybe.map String.toInt (Dict.get "t" args) of
Just (Just 0) ->
Nothing
Just (Just t) ->
Just t
_ ->
Nothing
-- String.split "/" (Maybe.withDefault "" (List.head splits))
( playlistName, videoName ) =
case split of
p :: v :: _ ->
@@ -114,7 +138,7 @@ update msg model =
case ( playlist, video ) of
( Just p, Just v ) ->
( Video p v
, Ports.registerVideo ( Twitch.videoId v, v.url )
, Ports.registerVideo ( Twitch.videoId v, v.url, time )
)
( Just p, Nothing ) ->
@@ -127,3 +151,18 @@ update msg model =
_ ->
( model, Cmd.none )
splitter : String -> Maybe ( String, String )
splitter input =
case String.split "=" input of
h :: t ->
Just ( h, String.join "=" t )
_ ->
Nothing
parseQueryString : String -> Dict String String
parseQueryString input =
Dict.fromList (List.filterMap splitter (String.split "&" input))
+1 -1
View File
@@ -1,4 +1,4 @@
port module Ports exposing (registerVideo)
port registerVideo : ( String, String ) -> Cmd msg
port registerVideo : ( String, String, Maybe Int ) -> Cmd msg