45 lines
824 B
Elm
45 lines
824 B
Elm
module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, update)
|
|
|
|
import Browser.Navigation
|
|
import Json.Decode as Decode
|
|
import Task
|
|
import Twitch
|
|
import Url
|
|
|
|
|
|
type FullModel
|
|
= Unloaded
|
|
| Loaded Model
|
|
|
|
|
|
type alias Model =
|
|
{ playlists : List Twitch.Playlist
|
|
, page : Page
|
|
}
|
|
|
|
|
|
type Page
|
|
= Home
|
|
|
|
|
|
type Msg
|
|
= Noop
|
|
| PlaylistsReceived (List Twitch.Playlist)
|
|
|
|
|
|
init : Decode.Value -> Url.Url -> Browser.Navigation.Key -> ( FullModel, Cmd Msg )
|
|
init _ _ _ =
|
|
( Unloaded
|
|
, Task.perform PlaylistsReceived Twitch.fetchPlaylists
|
|
)
|
|
|
|
|
|
update : Msg -> FullModel -> ( FullModel, Cmd Msg )
|
|
update msg model =
|
|
case msg of
|
|
Noop ->
|
|
( model, Cmd.none )
|
|
|
|
PlaylistsReceived playlists ->
|
|
( Loaded { playlists = playlists, page = Home }, Cmd.none )
|