Add draft CreateGame screen

web-client
Bram van den Heuvel 2026-06-19 13:46:13 +02:00
parent ecc69034f3
commit e2a11ae0d1
2 changed files with 66 additions and 2 deletions

View File

@ -6,7 +6,6 @@ module Match exposing (..)
import Api
import Duration exposing (Duration)
import Element exposing (Element)
import Element.Background
import Http
import Json.Decode as D
import Layout
@ -252,5 +251,5 @@ viewMenu :
, width : Quantity Int Pixels
}
-> Element (Msg gameState)
viewMenu data =
viewMenu _ =
Element.none

65
elm/Screen/CreateGame.elm Normal file
View File

@ -0,0 +1,65 @@
module Screen.CreateGame exposing (..)
-- MODEL
type alias Model =
{ baseUrl : String
, players : List String
}
type Msg
= OnBaseUrl String
| OnPlayer Int String
| RemovePlayer Int
-- UPDATE
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
OnBaseUrl url ->
( { model | baseUrl = url }, Cmd.none )
OnPlayer n p ->
let
newIndex = List.length model.players == n
newPlayers =
if newIndex && mayCreateNewPlayer model.players then
List.append model.players [ p ]
else
List.indexedMap
(\i player ->
if n == i then
p
else
player
)
model.players
in
( { model | players = newPlayers }, Cmd.none )
RemovePlayer n ->
( { model
| players =
model.players
|> List.indexedMap
(\i player ->
if n == i then
Nothing
else
Just player
)
|> List.filterMap identity
}
, Cmd.none
)
-- SUBSCRIPTIONS
-- VIEW
mayCreateNewPlayer : List String -> Bool
mayCreateNewPlayer =
List.all (not << String.isEmpty)