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.
68 lines
1.3 KiB
68 lines
1.3 KiB
module Model exposing (InitInfo, Model, initialModel)
|
|
|
|
import Browser.Navigation as Nav
|
|
import Http
|
|
import Navigation
|
|
import Participant exposing (Participant)
|
|
import Url exposing (Url)
|
|
|
|
|
|
type alias Uuid =
|
|
String
|
|
|
|
|
|
type alias Model =
|
|
{ key : Nav.Key
|
|
, apiHost : String
|
|
, route : Navigation.Route
|
|
, httpError : Maybe Http.Error
|
|
, me : Participant
|
|
, session : Maybe String
|
|
, participants : List Participant
|
|
}
|
|
|
|
|
|
type alias InitInfo =
|
|
{ navkey : Nav.Key
|
|
, route : Navigation.Route
|
|
, url : Url
|
|
, userUuid : String
|
|
}
|
|
|
|
|
|
initialModel : InitInfo -> Model
|
|
initialModel init =
|
|
Model
|
|
init.navkey
|
|
("//" ++ init.url.host ++ urlToPort init.url)
|
|
init.route
|
|
-- httpError
|
|
Maybe.Nothing
|
|
-- me
|
|
(Participant init.userUuid "")
|
|
-- session
|
|
Maybe.Nothing
|
|
-- participants
|
|
[]
|
|
|
|
|
|
urlToPort : Url -> String
|
|
urlToPort url =
|
|
case url.port_ of
|
|
Just p ->
|
|
let
|
|
isDebug =
|
|
p == 8000
|
|
|
|
portToUse =
|
|
if isDebug then
|
|
8080
|
|
|
|
else
|
|
p
|
|
in
|
|
":" ++ String.fromInt portToUse
|
|
|
|
Nothing ->
|
|
""
|