split things into separate pages
This commit is contained in:
parent
73aad7ab62
commit
18323543d0
|
@ -10,43 +10,14 @@ import Layout
|
|||
import Mi
|
||||
import Mi.Switch
|
||||
import Mi.WebMention
|
||||
import Model exposing (Model, Msg(..), init)
|
||||
import Page.Index
|
||||
import Page.Login
|
||||
import Route exposing (Route(..), routeParser)
|
||||
import Url exposing (Url)
|
||||
import Url.Parser as UrlParser exposing ((</>))
|
||||
|
||||
|
||||
{-| All of the data that the app can hold.
|
||||
-}
|
||||
type alias Model =
|
||||
{ navKey : Nav.Key
|
||||
, route : Maybe Route
|
||||
, token : Maybe String
|
||||
, tokenData : Maybe Mi.TokenData
|
||||
, error : Maybe String
|
||||
}
|
||||
|
||||
|
||||
init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init _ url key =
|
||||
( { navKey = key
|
||||
, route = UrlParser.parse routeParser url
|
||||
, token = Nothing
|
||||
, tokenData = Nothing
|
||||
, error = Nothing
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
type Msg
|
||||
= ChangeUrl Url
|
||||
| ClickLink UrlRequest
|
||||
| UpdateToken String
|
||||
| SubmitToken
|
||||
| ValidateToken (Result Http.Error Mi.TokenData)
|
||||
| ClearError
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
|
@ -85,7 +56,7 @@ update msg model =
|
|||
( model, Nav.load url )
|
||||
|
||||
ClearError ->
|
||||
( { model | error = Nothing, token = Nothing }, Cmd.none )
|
||||
( { model | error = Nothing }, Cmd.none )
|
||||
|
||||
|
||||
view : Model -> Document Msg
|
||||
|
@ -94,34 +65,10 @@ view model =
|
|||
Nothing ->
|
||||
case Maybe.withDefault Index model.route of
|
||||
Index ->
|
||||
case model.tokenData of
|
||||
Nothing ->
|
||||
Layout.basic "Login Required" []
|
||||
|
||||
Just data ->
|
||||
Layout.template "Mi"
|
||||
[ p
|
||||
[]
|
||||
[ span
|
||||
[]
|
||||
[ text "Subscriber: "
|
||||
, text data.sub
|
||||
, br [] []
|
||||
, text "Token ID: "
|
||||
, text data.jti
|
||||
, br [] []
|
||||
, text "Issuer: "
|
||||
, text data.iss
|
||||
]
|
||||
]
|
||||
]
|
||||
Page.Index.view model
|
||||
|
||||
Login ->
|
||||
Layout.basic "Login"
|
||||
[ p [] [ text "Enter the secret code. Unauthorized access is prohibited." ]
|
||||
, input [ placeholder "API Token", value (Maybe.withDefault "" model.token), onInput UpdateToken ] []
|
||||
, button [ onClick SubmitToken ] [ text "Login" ]
|
||||
]
|
||||
Page.Login.view model
|
||||
|
||||
_ ->
|
||||
Debug.todo "implement routing"
|
||||
|
@ -129,7 +76,7 @@ view model =
|
|||
Just why ->
|
||||
Layout.basic
|
||||
"Error"
|
||||
[ p [] [ text why ]
|
||||
[ p [] [ text why, text ". Please clear the error to proceed." ]
|
||||
, a [ onClick ClearError, href "/" ] [ text "Clear error" ]
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
module Model exposing (Model, Msg(..), init)
|
||||
|
||||
import Browser exposing (UrlRequest(..))
|
||||
import Browser.Navigation as Nav
|
||||
import Http
|
||||
import Mi
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= ChangeUrl Url
|
||||
| ClickLink UrlRequest
|
||||
| UpdateToken String
|
||||
| SubmitToken
|
||||
| ValidateToken (Result Http.Error Mi.TokenData)
|
||||
| ClearError
|
||||
|
||||
|
||||
init : () -> Url -> Nav.Key -> ( Model, Cmd msg )
|
||||
init _ url key =
|
||||
( { navKey = key
|
||||
, route = UrlParser.parse routeParser url
|
||||
, token = Nothing
|
||||
, tokenData = Nothing
|
||||
, error = Nothing
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
|
@ -0,0 +1,31 @@
|
|||
module Page.Index exposing (view)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Html exposing (br, p, span, text)
|
||||
import Layout exposing (basic, template)
|
||||
import Model exposing (Model)
|
||||
|
||||
|
||||
view : Model -> Document msg
|
||||
view { tokenData } =
|
||||
case tokenData of
|
||||
Nothing ->
|
||||
basic "Login Required" []
|
||||
|
||||
Just data ->
|
||||
template "Mi"
|
||||
[ p
|
||||
[]
|
||||
[ span
|
||||
[]
|
||||
[ text "Subscriber: "
|
||||
, text data.sub
|
||||
, br [] []
|
||||
, text "Token ID: "
|
||||
, text data.jti
|
||||
, br [] []
|
||||
, text "Issuer: "
|
||||
, text data.iss
|
||||
]
|
||||
]
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
module Page.Login exposing (view)
|
||||
|
||||
import Browser exposing (Document)
|
||||
import Html exposing (button, input, p, text)
|
||||
import Html.Attributes exposing (placeholder, value)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Layout exposing (basic, template)
|
||||
import Model exposing (Model, Msg(..))
|
||||
|
||||
|
||||
view : Model -> Document Msg
|
||||
view model =
|
||||
basic "Login"
|
||||
[ p [] [ text "Enter the secret code. Unauthorized access is prohibited." ]
|
||||
, input [ placeholder "API Token", value (Maybe.withDefault "" model.token), onInput UpdateToken ] []
|
||||
, button [ onClick SubmitToken ] [ text "Login" ]
|
||||
]
|
Loading…
Reference in New Issue