Skip to content

Commit

Permalink
add a retire button
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Aug 24, 2020
1 parent 1cbf8fd commit eb3bbcd
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Main.elm
Expand Up @@ -37,6 +37,7 @@ type alias Model =
type Msg
= KeeperUpdatedNewPlayerName String
| KeeperWantsToAddNewPlayer
| KeeperWantsToRetirePlayer Player
| StartMatchBetween ( Player, Player )
| MatchFinished Player Elo.Outcome Player
| KeeperWantsToSaveStandings
Expand Down Expand Up @@ -73,6 +74,25 @@ update msg model =
)
|> startNextMatchIfPossible

KeeperWantsToRetirePlayer player ->
( { model
| players = Dict.remove player.name model.players
, currentMatch =
case model.currentMatch of
Nothing ->
Nothing

Just ( a, b ) ->
if player == a || player == b then
Nothing

else
Just ( a, b )
}
, Cmd.none
)
|> startNextMatchIfPossible

StartMatchBetween players ->
( { model | currentMatch = Just players }
, Cmd.none
Expand Down Expand Up @@ -326,7 +346,7 @@ percent chanceToWin =
(toFloat (round (chanceToWin * 10000)) / 100 |> String.fromFloat) ++ "%"


rankings : List Player -> Html msg
rankings : List Player -> Html Msg
rankings players =
players
|> List.sortBy (\player -> -player.rating)
Expand All @@ -338,6 +358,11 @@ rankings players =
, Html.td [] [ Html.text player.name ]
, Html.td [] [ Html.text (String.fromInt player.rating) ]
, Html.td [] [ Html.text (String.fromInt player.matches) ]
, Html.td []
[ Html.button
[ Events.onClick (KeeperWantsToRetirePlayer player) ]
[ Html.text "Retire" ]
]
]
)
|> (::)
Expand All @@ -347,6 +372,7 @@ rankings players =
, Html.th [] [ Html.text "Name" ]
, Html.th [] [ Html.text "Rating" ]
, Html.th [] [ Html.text "Matches" ]
, Html.th [] [ Html.text "Actions" ]
]
)
|> Html.table []
Expand Down

0 comments on commit eb3bbcd

Please sign in to comment.