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
-}
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 _ =
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 )
3 years ago
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
)
3 years ago
Navigation.Poker session ->
( { model | route = route, session = Just session }
, Cmd.none
)
view : Model -> Browser.Document Msg
view model =
4 years ago
{ title = "Open-Retro"
, body =
[ nav []
[ h1 [ class "app-title" ] [ text "Open-Retro" ]
, ul []
[ li []
3 years ago
[ input [ class "board-search-input", placeholder "Session ID..." ] [] ]
, li []
[ text "🂿 New retro" ]
, li []
3 years ago
[ text "🃠 New poker" ]
]
]
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
3 years ago
Navigation.Poker _ ->
pokerPage model
homePage : Model -> List (Html Msg)
3 years ago
homePage _ =
[]
pokerPage : Model -> List (Html Msg)
pokerPage _ =
[]