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.

113 lines
2.6 KiB

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
-}
4 years ago
init : { userUuid : String } -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
init flags url key =
let
route : Navigation.Route
route =
Url.Parser.parse Navigation.routeParser url
|> Maybe.withDefault Navigation.Home
4 years ago
initInfo : Model.InitInfo
initInfo =
Model.InitInfo key route url flags.userUuid
model : Model
model =
4 years ago
Model.initialModel initInfo
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 =
4 years ago
{ title = "Open-Retro"
, body =
[ h1 [ class "app-title" ] [ text "Open-Retro" ]
, nav []
[ ul []
[ li []
[ input [ placeholder "Board ID..." ] []
]
, li []
[ text " New board"
]
]
]
4 years ago
, main_ [] (appContent model)
, node "link" [ rel "stylesheet", href "/compiled/css/style.css" ] []
]
}
appContent : Model -> List (Html Msg)
appContent model =
case model.route of
Navigation.Home ->
homePage model
homePage : Model -> List (Html Msg)
homePage model =
[]