Page type in Model

This commit is contained in:
dmitry 2020-11-23 16:31:31 +03:00
parent 4eac7dc2ac
commit 1adeb9afb9
5 changed files with 30 additions and 16 deletions

View File

@ -22,9 +22,11 @@ import Config exposing (Flags)
import Dict
import Model exposing (Model)
import Msg exposing (Msg(..))
import Route
import Subscriptions exposing (subscriptions)
import Update exposing (update)
import Url
import Url.Parser
import Utils.TaskExtras exposing (run)
import View exposing (view)
@ -43,12 +45,16 @@ main =
init : Flags -> Url.Url -> Navigation.Key -> ( Model, Cmd Msg )
init flags url key =
let
r =
Route.parse url
emptyModel =
{ peerId = flags.peerId
, relayId = flags.relayId
, url = url
, key = key
, page = r
, loadedPeers = Dict.empty
}
in
( emptyModel, run <| UrlChanged url )
( emptyModel, Route.routeCommand emptyModel r )

View File

@ -21,6 +21,11 @@ import Dict exposing (Dict)
import Url
type Route
= Page String
| Peer String
type alias PeerData =
{ interfaces : List String }
@ -30,5 +35,6 @@ type alias Model =
, relayId : String
, key : Nav.Key
, url : Url.Url
, page : Route
, loadedPeers : Dict String PeerData
}

View File

@ -2,16 +2,11 @@ module Route exposing (..)
import Air exposing (call, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode as Encode
import Model exposing (Model)
import Model exposing (Model, Route(..))
import Port exposing (sendAir)
import Url.Parser exposing ((</>), Parser, map, oneOf, s, string)
type Route
= Page String
| Peer String
routeParser : Parser (Route -> a) a
routeParser =
oneOf
@ -20,6 +15,10 @@ routeParser =
]
parse url =
Maybe.withDefault (Page "") <| Url.Parser.parse routeParser url
routeCommand : Model -> Route -> Cmd msg
routeCommand m r =
case r of

View File

@ -24,7 +24,6 @@ import Msg exposing (..)
import Port exposing (sendAir)
import Route
import Url
import Url.Parser
update : Msg -> Model -> ( Model, Cmd Msg )
@ -36,7 +35,7 @@ update msg model =
UrlChanged url ->
let
route =
Maybe.withDefault (Route.Page "") <| Url.Parser.parse Route.routeParser url
Route.parse url
cmd =
Route.routeCommand model route

View File

@ -24,6 +24,7 @@ import Model exposing (Model)
import Msg exposing (..)
import Palette exposing (classes)
view : Model -> Document Msg
view model =
{ title = title model, body = [ body model ] }
@ -36,15 +37,18 @@ title _ =
body : Model -> Html Msg
body model =
layout <|
layout <|
List.concat
[
[-- TODO render the view according to model.page
]
layout : List (Html Msg) -> Html Msg
layout elms =
div [classes "mw9 center"]
[div [classes "fl w-100 pa2"] ([
header [classes "w-100 bt bb b--black-10", onClick Click] [text "Fluence Network Dashboard"]
] ++elms)]
div [ classes "mw9 center" ]
[ div [ classes "fl w-100 pa2" ]
([ header [ classes "w-100 bt bb b--black-10", onClick Click ] [ text "Fluence Network Dashboard" ]
]
++ elms
)
]