Support time
This commit is contained in:
+42
-3
@@ -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
@@ -1,4 +1,4 @@
|
||||
port module Ports exposing (registerVideo)
|
||||
|
||||
|
||||
port registerVideo : ( String, String ) -> Cmd msg
|
||||
port registerVideo : ( String, String, Maybe Int ) -> Cmd msg
|
||||
|
||||
Reference in New Issue
Block a user