mi/sina/src/Model.elm

86 lines
2.2 KiB
Elm
Raw Normal View History

2020-11-16 20:25:48 +00:00
module Model exposing (Model, Msg(..), get, init)
2020-11-16 03:09:53 +00:00
import Browser exposing (UrlRequest(..))
import Browser.Navigation as Nav
import Http
import Mi
2020-11-16 21:00:55 +00:00
import Mi.POSSE
import Mi.PackageTracking.OrangeConnex as OrangeConnex
2020-11-16 15:10:57 +00:00
import Mi.Switch exposing (Switch)
import Mi.WebMention exposing (WebMention)
2020-11-16 03:09:53 +00:00
import Route exposing (Route, routeParser)
import Url exposing (Url)
import Url.Parser as UrlParser
type alias Model =
{ navKey : Nav.Key
, route : Maybe Route
, token : Maybe String
, tokenData : Maybe Mi.TokenData
, error : Maybe String
2020-11-16 15:10:57 +00:00
, front : Maybe Switch
, switchPage : Int
, switches : List Switch
, webMentionPage : Int
, webMentions : List WebMention
, switchByID : Maybe Switch
, webMentionByID : Maybe WebMention
2020-11-16 21:00:55 +00:00
, post : Mi.POSSE.Post
, ocTrackingID : Maybe String
, ocPackages : Maybe (List OrangeConnex.Package)
, ocTraces : Maybe (List OrangeConnex.Trace)
2020-11-16 03:09:53 +00:00
}
2020-11-16 20:25:48 +00:00
get : Model -> String -> Http.Expect Msg -> Cmd Msg
get model url action =
Mi.request
"GET"
(Maybe.withDefault "" model.token)
url
Http.emptyBody
action
2020-11-16 03:09:53 +00:00
type Msg
= ChangeUrl Url
| ClickLink UrlRequest
| UpdateToken String
| SubmitToken
2020-11-16 15:10:57 +00:00
| FetchSwitch String
2020-11-16 16:26:03 +00:00
| NextSwitchesPage
| PrevSwitchesPage
| FetchOCPackages
| FetchOCTraces String
2020-11-16 03:09:53 +00:00
| ValidateToken (Result Http.Error Mi.TokenData)
2020-11-16 15:10:57 +00:00
| ValidateSwitchByID (Result Http.Error Switch)
| ValidateFront (Result Http.Error Switch)
| ValidateSwitches (Result Http.Error (List Switch))
| ValidateOCPackages (Result Http.Error (List OrangeConnex.Package))
| ValidateOCTraces (Result Http.Error (List OrangeConnex.Trace))
2020-11-16 03:09:53 +00:00
| ClearError
init : () -> Url -> Nav.Key -> ( Model, Cmd msg )
init _ url key =
( { navKey = key
, route = UrlParser.parse routeParser url
, token = Nothing
, tokenData = Nothing
, error = Nothing
2020-11-16 15:10:57 +00:00
, front = Nothing
, switchPage = 1
, switches = []
, webMentionPage = 1
, webMentions = []
, switchByID = Nothing
, webMentionByID = Nothing
2020-11-16 21:00:55 +00:00
, post = Mi.POSSE.init
, ocTrackingID = Nothing
, ocPackages = Nothing
, ocTraces = Nothing
2020-11-16 03:09:53 +00:00
}
2020-11-16 15:10:57 +00:00
, Nav.pushUrl key "/login"
2020-11-16 03:09:53 +00:00
)