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)