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.

140 lines
3.1 KiB

port 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
}
port wsout : String -> Cmd msg
port wsin : (String -> msg) -> Sub msg
{-| currently no flags are needed
that's the reason for the generic type and \_ as param name
-}
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
initInfo : Model.InitInfo
initInfo =
Model.InitInfo key route url flags.userUuid
model : Model
model =
Model.initialModel initInfo
in
routeChanged route model
subscriptions : Model -> Sub Msg
subscriptions _ =
wsin WsIn
type Msg
= UrlChanged Url.Url
| LinkClicked Browser.UrlRequest
| WsIn String
| WsOut String
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 )
WsOut wsmsg ->
( model, wsout wsmsg )
WsIn strmsg ->
( model, Cmd.none )
routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg )
routeChanged route model =
case route of
Navigation.Home ->
( { model | route = route }
, Cmd.none
)
Navigation.Poker session ->
( { model | route = route, session = Just session }
, Cmd.none
)
view : Model -> Browser.Document Msg
view model =
{ title = "Open-Retro"
, body =
[ nav []
[ h1 [ class "app-title" ] [ text "Open-Retro" ]
, ul []
[ li []
[ input [ class "board-search-input", placeholder "Session ID..." ] [] ]
, li []
[ text "🂿 New retro" ]
, li []
[ text "🃠 New poker" ]
]
]
, 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
Navigation.Poker _ ->
pokerPage model
homePage : Model -> List (Html Msg)
homePage _ =
[]
pokerPage : Model -> List (Html Msg)
pokerPage _ =
[]