You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.3 KiB
104 lines
2.3 KiB
4 years ago
|
module Main exposing (main)
|
||
|
|
||
|
import Browser
|
||
|
import Browser.Navigation as Nav
|
||
|
import Html exposing (..)
|
||
|
import Html.Attributes exposing (..)
|
||
|
import Model exposing (Model)
|
||
|
import Navigation
|
||
|
import Url
|
||
|
import Url.Parser
|
||
|
|
||
|
|
||
|
main =
|
||
|
Browser.application
|
||
|
{ init = init
|
||
|
, onUrlChange = UrlChanged
|
||
|
, onUrlRequest = LinkClicked
|
||
|
, subscriptions = subscriptions
|
||
|
, update = update
|
||
|
, view = view
|
||
|
}
|
||
|
|
||
|
|
||
|
{-| currently no flags are needed
|
||
|
that's the reason for the generic type and \_ as param name
|
||
|
-}
|
||
|
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
||
|
init _ url key =
|
||
|
let
|
||
|
route : Navigation.Route
|
||
|
route =
|
||
|
Url.Parser.parse Navigation.routeParser url
|
||
|
|> Maybe.withDefault Navigation.Home
|
||
|
|
||
|
model : Model
|
||
|
model =
|
||
|
Model.initialModel key route url
|
||
|
in
|
||
|
routeChanged route model
|
||
|
|
||
|
|
||
|
subscriptions : Model -> Sub Msg
|
||
|
subscriptions _ =
|
||
|
Sub.none
|
||
|
|
||
|
|
||
|
type Msg
|
||
|
= UrlChanged Url.Url
|
||
|
| LinkClicked Browser.UrlRequest
|
||
|
|
||
|
|
||
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||
|
update msg model =
|
||
|
case msg of
|
||
|
-- Navigation based messages
|
||
|
LinkClicked urlRequest ->
|
||
|
Navigation.linkClicked urlRequest model.key model
|
||
|
|
||
|
UrlChanged url ->
|
||
|
case Url.Parser.parse Navigation.routeParser url of
|
||
|
Just route ->
|
||
|
routeChanged route model
|
||
|
|
||
|
Nothing ->
|
||
|
-- TODO error reporting
|
||
|
( { model | route = Navigation.Home }, Cmd.none )
|
||
|
|
||
|
|
||
|
routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg )
|
||
|
routeChanged route model =
|
||
|
case route of
|
||
|
Navigation.Home ->
|
||
|
( { model | route = route }
|
||
|
, Cmd.none
|
||
|
)
|
||
|
|
||
|
|
||
|
view : Model -> Browser.Document Msg
|
||
|
view model =
|
||
|
{ title = "OpenAgile"
|
||
|
, body =
|
||
|
[ h1 [] [ text "OpenAgile" ]
|
||
|
, div [ class "content" ]
|
||
|
[ nav [] [ Navigation.navTree ]
|
||
|
, main_ [] (appContent model)
|
||
|
]
|
||
|
, node "link" [ rel "stylesheet", href "/assets/style.css" ] []
|
||
|
]
|
||
|
}
|
||
|
|
||
|
|
||
|
appContent : Model -> List (Html Msg)
|
||
|
appContent model =
|
||
|
case model.route of
|
||
|
Navigation.Home ->
|
||
|
homePage model
|
||
|
|
||
|
|
||
|
homePage : Model -> List (Html Msg)
|
||
|
homePage model =
|
||
|
[ h2 [] [ text "Home" ]
|
||
|
]
|
||
|
|